var name = "#floatMenu";
var menuYloc = null;
$(document).ready(function () {
menuYloc = parseInt($(name).css("top").substring(0, $(name).css("top").indexOf("px")))
$(window).scroll(function () {
var offset = menuYloc + $(document).scrollTop() + "px";
$(name).animate({ top: offset }, { duration: 500, queue: false });
});
How can i create a floating button using jQuery and CSS?
You could achieve a floating button much simpler with css
position: fixed; top: 100px; left: 100px. This would always be visible when you scroll the page and on the same spot.