当光标位于顶部的蓝色块上方时无法滚动,任何关于我哪里出错的想法?
HTML
<div class="wrapper">
<div class="block">
block
</div>
<div class="content">
content
</div>
</div>
CSS
body {
margin: 0px;
padding: 0px;
}
.block {
background: blue;
height: 300px;
width: 100%;
position: fixed;
}
.content {
background: red;
margin-top: 300px;
top: 0;
width: 100%;
height: 100%;
z-index: 100;
position: absolute;
}
.wrapper {
position: absolute;
width: 100%;
height: 100%;
overflow: auto;
}
JS
$(".wrapper").scrollTop(300);
答案 0 :(得分:0)
您使用了css position: Fixed;
,因此类block
不会从其位置移动,滚动条将无法在mousehover
事件
<强> HTML 强>
<div class="wrapper">
<div class="block">
block
</div>
<div class="content">
content
</div>
</div>
<强> CSS 强>
body {
margin: 0px;
padding: 0px;
}
.block {
background: blue;
height: 300px;
width: 100%;
position: absolute;
}
.content {
background: red;
margin-top: 300px;
top: 0;
width: 100%;
height: 100%;
z-index: 100;
position: absolute;
}
.wrapper {
background: #ccc none repeat scroll 0 0;
width: 100%;
height: 100%;
overflow: auto;
}
<强> JS 强>
$( ".wrapper" ).scrollTop( 300 );
这里是fiddle
答案 1 :(得分:0)
由于你有为类块固定的位置,它将阻止滚动条工作。所以改变类块的位置。
答案 2 :(得分:0)
删除包装div并将“body”添加到javascript
更新 http://jsfiddle.net/cr8uj/7/
<强> JS 强>
$( "body" ).scrollTop( 300 );
答案 3 :(得分:0)
please do not use fixed property on .block class
body {
margin: 0px;
padding: 0px;
}
.block {
background: blue;
height: 300px;
width: 100%;
position: absolute;
}
.content {
background: red;
margin-top: 300px;
top: 0;
width: 100%;
height: 100%;
z-index: 100;
position: absolute;
}
.wrapper {
position: absolute;
width: 100%;
height: 100%;
overflow: auto;
}