0
我需要以一種簡單的方式處理水平和垂直滾動,這對一般的Safari移動設備以及特殊的iPad都有效。如何在Safari移動版(iPad)上正確滾動?
我有一個非常簡單的HTML/CSS框架,我想保持非常簡單的描述如下。
水平滾動條
不幸的是,這需要我計算滾動條的寬度,根據不同的內容。有沒有一種自動方式?
的HTML如下:
<div class="scrollerContainer hScrollable">
<div class="scroller">
<div id="photo1"></div>
<div id="photo2"></div>
<div id="photo3"></div>
<div id="photo4"></div>
<div id="photo5"></div>
<div id="photo6"></div>
<div id="photo7"></div>
<div id="photo8"></div>
<div id="photo9"></div>
</div>
</div>
和相關的CSS如下:
.hScrollable {
overflow-x: scroll;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
white-space:nowrap;
}
scrollerContainer {
-webkit-box-sizing: border-box;
width: 100%;
height: 50px;
margin: 0;
border: solid 1px black;
}
.scroller {
-webkit-box-sizing: border-box;
margin: 0;
padding: 4px;
white-space: nowrap;
overflow: hidden; /* Really important to avoid vertical scrolling on devices */
width: 100%;
height: 50px;
background-color: lightgray;
}
.scroller>div {
width: 50px;
height: 50px;
display: inline-block;
}
垂直卷軸
我想的內容來填充父容器並超過垂直尺寸,垂直滾動。
的HTML如下:
<div id="container" style="height:400px">
<div style="height:100px">
Fixed content, I dont want to vscroll
</div>
<div class="tabContent">
Potentially long content that should vscroll.
This div should fill to the end of the container.
I don't want to set its height to 300px,
but to find a way it does automatically.
</div>
</div>
謝謝你@theJoeBiz你回答了我的問題1)(水平卷軸)。但我仍然有垂直滾動問題(小提琴的第二個和第三個標籤)。我試圖將你的解決方案翻譯成它沒有成功。這裏是更新的小提琴http://jsfiddle.net/stephanedeluca/56gFf/14/ –
@StéphanedeLuca您的高度問題是,您的.scroller設置爲50px的高度。如果將其改爲最小高度,.scroller將始終至少爲50px,但如果滾動條出現(爲了適應滾動條的高度),它實際上最終會變得更高。我還將overflow-x更改爲.hScrollable自動,以便除非內容大於100%,否則不會顯示滾動條。 http://jsfiddle.net/56gFf/15/ – theJoeBiz
我的觀點是關於與tabContent(在相同的填充)相關聯的垂直滾動器(類vScrollable)。當您點擊/單擊第三個選項卡時,可以很好地展示這一點:當按照vScrollable類的要求滾動時,tabContent的內容會垂直溢出。它是如何來的? @theJoeBiz –