我在我的側邊欄中使用jQuery浮動小部件 - 鏈接到我的文章http://www.product-investigation.com/fat-loss-factor-review - 如果向下滾動,您可以看到我的意思..我想在頁腳之前停止我的adsense小部件...感謝您的幫助:)位置:固定在側邊欄 - 如何在頁腳之前停止它?
我的JavaScript
<script>
$(document).ready(function() {
function isScrolledTo(elem) {
var docViewTop = $(window).scrollTop(); //num of pixels hidden above current screen
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top; //num of pixels above the elem
var elemBottom = elemTop + $(elem).height();
return ((elemTop <= docViewTop));
}
var catcher = $('#catcher');
var sticky = $('#sticky');
$(window).scroll(function() {
if(isScrolledTo(sticky)) {
sticky.css('position','fixed');
sticky.css('top','100px');
}
var stopHeight = catcher.offset().top + catcher.height();
if (stopHeight > sticky.offset().top) {
sticky.css('position','absolute');
sticky.css('top',stopHeight);
}
});
});
</script>
你有沒有試過把'if(isScrolledTo(sticky))'放在'else'語句中?有點像'if(stopHeight> sticky.offset()。top){...} else {if(isScrolledTo(sticky)){...}} .. – dunli
不適用於我: – Chymmi
呃.. 。你能設置[jsfiddle](http://jsfiddle.net)嗎?我可以幫助你調試你的問題嗎? – dunli