javascript - How to achieve floating div on scrolldown -
i newbie on jquery, , want div hang on top of screen when page scrolldown more 50, how can achieve this?
i want div absolute , not fixed.
$(document).ready(function () { $(window).scroll(function () { if ($(window).scrolltop() > 50) { $(".articlebutton").css("top", "0px"); //i want value change dynamically scrollbar moves down, div stays on top of screen } else { $(".articlebutton").css("top", "-50px"); } }); });
you can set position top -100 since -50 , scroll occurs after 50:
$(".articlebutton").css("top", ($(window).scrolltop()-100)+"px");
Comments
Post a Comment