我正在使用一个滚动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
距离处开始?
如果内容宽度小于浏览器宽度,剩余的滚动区域会填充 75px 的 div。
因此,HTML 如下:
HTML
<div class="scrollableArea">
<img/>
<img/>
<img/>
<div class="filler"/>
<div class="filler"/>
<div class="filler"/>
<div class="filler"/>
...etc
</div>