这是一款可以使任何文字和图片列表进行水平和垂直滚动的jQuery插件。该jquery图片滚动插件的特点和一些注意事项如下:
先用一张图来描述该jQuery插件的工作原理。
在下面给出html结构中.als-container
、.als-viewport
、.als-wrapper
和.als-item
是必须的结构。.als-prev
和.als-next
是可选的。
<!-- define a container with class "als-container": this will be the object binded to ALS; we suggest to give it an ID to retrieve it easily during ALS inizialization --> <div class="als-container" id="my-als-list"> <!-- if you choose manual scrolling (which is set by default), insert <span> with class "als-prev" and "als-next": they define the buttons "previous" and "next"; within the <span> you can use images or simple text --> <span class="als-prev"><img src="images/prev.png" alt="prev" title="previous" /></span> <!-- define a container with class "als-viewport": this will be the viewport for the list visible elements --> <div class="als-viewport"> <!-- define a container with class "als-wrapper": this will be the wrapper for the list elements, it can be a classic <ul> element or even a <div> element --> <ul class="als-wrapper"> <!-- define the list elements, each must have class "als-item"; they can be classic <li> elements or generic <div> elements and they can contain anything: text, images, ... --> <li class="als-item">orange</li> <!-- text only --> <li class="als-item"><img src="images/fruits/apple.png" alt="apple" title="apple" /></li> <!-- image --> <li class="als-item"><img src="images/fruits/banana.png" alt="banana" title="banana" />banana</li> <!-- image + text --> </ul> <!-- als-wrapper end --> </div> <!-- als-viewport end --> <span class="als-next"><img src="images/next.png" alt="next" title="next" /></span> <!-- "next" button --> </div> <!-- als-container end -->
建议使用下面的CSS样式作为该列表滚动jQuery插件的通用样式,然后再各种情况设置不同元素的样式。
/***************************************************** * generic styling for ALS elements: outer container *****************************************************/ .als-container { position: relative; width: 100%; margin: 0px auto; z-index: 0; } /**************************************** * viewport styling ***************************************/ .als-viewport { position: relative; overflow: hidden; margin: 0px auto; } /*************************************************** * wrapper styling **************************************************/ .als-wrapper { position: relative; /* if you are using a list with
首先要引入必要的文件。
<!-- basic ALS css --> <link rel="stylesheet" type="text/css" media="screen" href="path/css/als_style.css" /> <!-- your jQuery version --> <script type="text/javascript" src="path/js/jquery-last.min.js" ></script> <!-- your ALS version --> <script type="text/javascript" src="path/js/jquery.als-1.6.min.js" ></script>
然后可以按下面的方法调用该插件:
在这个例子中我们有4个可见列表元素,滚动步长为2,滚动方向为水平方向,无限循环滚动并且自动循环模式,时间间隔为6秒,滚动速度为400毫秒,easing效果为 "linear" ,列表从右向左滚动,开始列表项为第二个元素。
$("#my-als-list").als({ visible_items: 4, scrolling_items: 2, orientation: "horizontal", circular: "yes", autoscroll: "yes", interval: 6000, speed: 400, easing: "linear", direction: "right", start_from: 1 });