我正在使用一个 JQuery 滚动插件,它可以在一个 div 中滚动图像,有点像选取框。 我正在尝试实现同样的事情,但是我想滚动 div 标签而不是 img 标签。
目前这是标记
<div id="contentscroller" style="clear:both;">
<div id='left' class="logo-carousel">
<div class="logo-test"></div>
<img src='/images/lve.png' />
<img src='/images/friendslife.png' />
<img src='/images/aviva.png' />
<img src='/images/bright-grey.png'/>
<img src='/images/sagicor.png'/>
<img src='/images/zurich.png'/>
<img src='/images/legal-general.png'/>
<img src='/images/groupama.png'/>
<img src='/images/fortress.png'/>
</div>
</div>
这是JS
<script>
$(
function () {
$("#left").imageScroller({ loading: 'Wait please...' });
$("#right").imageScroller({ speed: '4000', direction: 'right' });
$("#top").imageScroller({ direction: 'top' });
$("#bottom").imageScroller({ speed: '3500', direction: 'bottom' });
}
)
</script>
我需要实现相同的目的,但只需使用带有背景图像的 div 元素。结果将完全相同,但我会使用带有图像的空 div 作为背景,而不是图像,以避免 HTTP 请求并加快网站性能。
我尝试用 div 替换图像,但是它不起作用,因为 JS 专门针对 contentscroller div 中的 img 标签。
最佳答案
修改原始库不是最佳答案,但这是我想建议的,因为该库只是查找图像而不是 div。看看它的一些source :
$.each($this.children( ":not(div)" ), function() ...
这很简单,库不是在寻找 div... 周围的工作是什么?根据他们的想法创建您自己的图书馆。
关于javascript - 在 div 内滚动 div 而不是 img 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19315221/