2013-01-23 40 views
0

我正在尋找添加滾動效果,當滾輪被釋放時捕捉到div的頂部。唯一的問題是每個div具有100%的高度(因此一次將在屏幕上顯示一個圖像)。
我遇到了這個小提琴:http://jsfiddle.net/djsbaker/dxzk4/這似乎很好地與300px間隔,但如何能這樣的東西被翻譯成100%高度的div?

這裏是我的代碼:滾動捕捉對100%高度的div的影響

<div class="fill-browser" style="background-image: url(../images/background-v2.jpg)"></div> 
<div class="fill-browser" style="background-image: url(../images/background-v2.jpg)"></div> 
<div class="fill-browser" style="background-image: url(../images/background-v2.jpg)"></div> 

CSS:

.fill-browser{ 
    position:relative; 
    left: 1%; 
    height:98%; 
    width:98%; 
    margin-bottom: 5px; 
    background: no-repeat 50% 50%; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
      } 

這裏有一個的jsfiddle演示過:http://jsfiddle.net/vHAWW/

回答

0

它與100%也

取決於有多少你需要將箱子的父母高度設置爲箱子* 100,箱子高度HTS到100 /盒,也不要忘了讓身體和HTML 100%。

jsfiddle.net/WQtA8

body, html { 
    height:100%; 
} 
.box 
{ 
    color: #fff; 
    height: 10%; 
    width: 300px; 
    border: 1px solid white; 
} 
#container { 
    height:1000%; 
    width:300px; 
    background-color:blue; 
} 
.red {background-color:red;} 
.green {background-color:green;} 
.yellow {background-color:yellow;} 

編輯:

因爲你使用jQuery媒體鏈接,還不如計算和動態設置高度:

$(document).ready(function() { 

var boxes = $(".box").length; 
var height = boxes * 100 + "%"; 
var boxheight = 100/boxes + "%"; 
$("#container").css({ height : height }); 
    $(".box").css({height: boxheight}); 
}); 
+0

將在此代碼工作我的jsfiddle:http://jsfiddle.net/vHAWW/似乎無法讓它工作? – user1374796

+0

它將與任何小提琴一起工作。你沒注意到那些小提琴中的js有什麼不同嗎?採取工作,並將其應用到你自己的:)專家提示:確保課程和元素referrarys在juery匹配你的htmls! – user1721135

+0

是的,當然,並感謝你的方式:)但那個小提琴你張貼,而divs現在可能是100%的高度,他們仍然是每隔300px? – user1374796