Code Jquery
1 2 3 4 5 6 7 8 9 10 |
$(window).scroll(function(){ var show = $(window).scrollTop() + $(window).height(); var hide = $(document).height() - $('footer').height(); var height = $(document).height() - show; $('.div_backtop').css("bottom",$('footer').height() - height); if(show<hide || $(window).width()<=767){ $('.div_backtop').css("bottom",20); // NẾU MÀN HÌNH SP THÌ CANH BOTTOM 20PX } }) |
Trong đó $(‘.div_backtop’) là nút backtop
$(‘footer’) là footer mà mình muốn nút backtop đi theo
Xem ví dụ để hiểu thêm