滚动y,但固定到x - bug在ios
Scroll y but fixed to x - buggy in ios
我使用一些javascript来保持我的div固定时水平滚动,但随着内容垂直滚动时滚动。
我唯一的问题是,当我在ipad上查看它时,我向右和向左滚动,div消失,直到滚动动作停止,然后在你停止滚动后返回到正确的位置。
有没有办法在ipad上解决这个问题?
这是我正在使用的代码。
CSS:#header {
top: 15px;
left: 15px;
position: absolute;
width: 100px;
height: 100px;
}
#longDiv {
margin: 100px 0 0 0;
width: 140%;
height: 4000px;
border: 1px #000 solid;
background:grey;
}
HTML:<div id="header">
Haha, I am a header. Nah.. Nah na na na
</div>
<div id="longDiv">
I am a bit of buffer test
</div>
脚本:
$(window).scroll(function(){
$('#header').css({
'left': $(this).scrollLeft() + 15 //Why this 15, because in the CSS, we have set
left 15, so as we scroll, we would want this to remain at 15px left
});
});
这里是jsfiddle http://jsfiddle.net/susannalarsen/05b9Lnng/1/
看来你想要实现的可以用CSS完成,没有必要用JS。
为什么不这样做呢?