Tạo nút Scroll to Top với jQuery cho Website

Code chèn trước thẻ </body>

<div id="topcontrol" title="Scroll to Top"><i class="fa fa-angle-up fa-lg fa-angle-style"></i></div>
<script>
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('#topcontrol').css({bottom:"15px"});
} else {
$('#topcontrol').css({bottom:"-100px"});
}
});
$('#topcontrol').click(function(){
$('html, body').animate({scrollTop: '0px'}, 800);
return false;
});
</script>

Demo: http://g-shock.vn

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar