I have a button that's fixed on the bottom right side of the page;
.btn-this{
width: 313px;
height: 61px;
background-color: #ebb762;
position: fixed;
bottom: 0;
right: 0;
z-index: 99;
}
And so i wanted to change the position of the button from 'fixed' to 'relative' after scrolling at a certain point of the page;
Now at first i had this work out for me:
JQuery(function ($) {
var masinfo = $(".btn-this");
$(window).scroll(function () {
var scroll = $(window).scrollTop();
if (scroll >= 457) {
masinfo.css('position', 'relative');
} else {
masinfo.css({
position: 'fixed',
bottom: '0'
});
}
});
});
But then i did see that this was not a quality solution , since i would have to paste and change the code for each page, and it would never be smooth.
So i did check this two posts:
Check if a user has scrolled to the bottom
But then again , i couldn't make it work smoothly, the code works, but it executes a lot of time,
when using:
if ($(window).scrollTop() + $(window).height() > $(document).height() - 78) {
console.log('bottom');
}
the console logs "bottom" 11 times;
I tried using a debouncer, but i just didn't understand the concept or just didn't do it the right way;
Has anyone been able to do something like this?