Skip to content

Instantly share code, notes, and snippets.

@juliankoehn
Last active October 21, 2015 14:27
Show Gist options
  • Save juliankoehn/afb6f8695d0823e05065 to your computer and use it in GitHub Desktop.
Save juliankoehn/afb6f8695d0823e05065 to your computer and use it in GitHub Desktop.
Go2Top Element
<div class="go2top">
<i class="fa fa-arrow-up"></i>
</div>
var Go2Top = function() {
var handle = function () {
var currentWindowPosition = $(window).scrollTop();
if (currentWindowPosition > 300) {
$(".go2top").show();
} else {
$(".go2top").hide();
}
};
return {
init: function () {
handle();
if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) {
$(window).bind("touchend touchcancel touchleave", function (e) {
handle();
});
} else {
$(window).scroll(function () {
handle();
});
}
$(".go2top").on('click', function (e) {
e.preventDefault();
$("html, body").animate({
scrollTop: 0
}, 600);
});
}
};
}();
$(function(){ Go2Top.init(); });
.go2top {
display: inline-block;
position: fixed;
bottom: 20px;
right: 10px;
cursor: pointer;
i {
opacity: 0.5;
filter: alphaopacity=50;
color: #89939e;
font-size: 38px;
font-weight: 300;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment