我想我的固定div停止滾動在我的網頁上的某個點,但是,我找到的解決方案都沒有實際運作正常,並做了我想要的...固定的Div停止在某些點jQuery
這是我目前的jQuery:
var windw = this;
$.fn.followTo = function (pos) {
var $this = this, $window = $(windw);
$window.scroll(function(e){
if ($window.scrollTop() > pos) {
$this.css({
position: 'absolute',
top: pos
});
} else {
$this.css({
position: 'fixed',
bottom: -10px
});
}
});
};
$('#qF').followTo(800);
這是我的HTML:
<div id="qF" class="central theater-dir-adown">
<img src="data/img/prefs/dir_adown" class="dir-adown">
</div>
這是我的CSS:
.theater-dir-adown{
cursor: pointer;
display: inline-block;
position: fixed;
bottom: -10px;
left: calc(100%/2 - 51px);
width: calc(75%/9);
height: auto;
}
.dir-adown{
width: 100%;
}
所以我想要的是停止滾動800px的div #qF
,但我使用的代碼不工作,div將繼續向下滾動頁面。我不確定在我的代碼中是否有某種錯誤,但有人可以幫我解決嗎?還是很新的jQuery的..
感謝
滾動刪除';''從底部:-10px;' –
@NirmalyaGhosh沒有工作,抱歉地說:(仍無法工作,因爲我t應該 –
從底部移除'px':-10px'它會拋出錯誤'Uncaught SyntaxError:Unexpected identifier'。工作:http://output.jsbin.com/latuji –