Last active
October 21, 2015 14:27
-
-
Save juliankoehn/afb6f8695d0823e05065 to your computer and use it in GitHub Desktop.
Go2Top Element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="go2top"> | |
<i class="fa fa-arrow-up"></i> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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