问题
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