How do I get the scrollToFix plugin limit to stop at my website's footer?

寵の児 提交于 2019-12-11 16:52:22

问题


I am using the scrollToFix script on my website to fix the ads as the user scrolls down the page as well as release when the user reaches the footer (so that the ads do not overlap the footer). My code below, however, causes the ads to stop scrolling between a third and half way down the page, rather than at the footer. Setting it to scroll to the outerHeight of the container minus the height of the footer leaves it stopping at that spot as well.

$(document).ready(function() {
     $('.right').scrollToFixed({
          marginTop: $('.float').outerHeight() + 8, 
          limit: $('footer').offset().top 
     });
});

Are there any ideas on how to get it to stop more accurately?


回答1:


It's probably because your site changes height after the document is ready, due to fonts & images etc. Try binding the event to the window load event.

$(function() {
    $('window').on('load', function() {
        $('.right').scrollToFixed({
            marginTop: $('.float').outerHeight() + 8, 
            limit: $('footer').offset().top 
        });
    });
});



回答2:


$(document).ready(function() {
     $('.right-sidebar').scrollToFixed({
     marginTop: 0,
     limit: $('.right-sidebar-parent').outerHeight() - 180 } );
    });

This worked for me for limiting the height dynamically.



来源:https://stackoverflow.com/questions/13615329/how-do-i-get-the-scrolltofix-plugin-limit-to-stop-at-my-websites-footer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!