【发布时间】:2013-08-19 01:17:50
【问题描述】:
我正在使用滚动 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>
【问题讨论】:
标签: javascript jquery smooth-scrolling