2014-01-18 65 views
1

當光標位於頂部的藍色塊上時無法滾動,關於我要去哪裏的錯誤的任何想法?無法在頂部div中滾動

JSFiddle Demo

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

您已經使用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

+0

我需要的塊是固定的,是有任何其他方式嗎? – Rob

+0

檢查鏈接http://jsfiddle.net/cr8uj/8/它的不固定 –

0

你有位置被固定類塊它會阻止滾動條的工作。所以改變類塊的位置。

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; 
}