我使用的是滚动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/