我使用的是滾動jquery插件,滾動的寬度是瀏覽器的寬度,所以當我的瀏覽器寬度小於內容寬度時,我希望內容從瀏覽器的中心開始。平滑滾動以在中心開始?
下面是我對用於居中內容的像素數量的看法。
JQUERY
var totalWidth = 0;
$('.scrollableArea img').each(function(){
totalWidth += parseInt($(this).width(), 10);
});
//totalWidth is the width of the content
var containWidth = $('#makeMeScrollable').width(); //browser width
containWidth /= 2;
totalWidth /= 2;
startWidth = containWidth - totalWidth;
有沒有什麼辦法可以讓它如此滾動內容開始startWidth
從左邊走呢?
如果內容寬度小於瀏覽器寬度,則scrollDiv的其餘部分用75px的div填充。
所以HTML看起來像
HTML
<div class="scrollableArea">
<img/>
<img/>
<img/>
<div class="filler"/>
<div class="filler"/>
<div class="filler"/>
<div class="filler"/>
...etc
</div>
這裏是插件網站http://www.smoothdivscroll.com/