jquery tools 系列 scrollable(2) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
scrollable提供的一系列获取scrollable对象的方法具体使用方式如下: 复制代码 代码如下: var scrollable=$("div.scrollable").scrollable(); //alert(scrollable.getConf().prev);//获取配置对象中的prev属性 scrollable.getConf().speed=200;//设置配置对象的speed属性 //alert(scrollable.getIndex());//获取当前滚动项的索引 //alert(scrollable.getItems().length);//获取当前滚动项的数量 //alert(scrollable.getItemWrap().html());//获取包含滚动项的节点(class=scrollable),并将所有滚动项显示出来 //alert(scrollable.getPageAmount());//获取当前滚动栏分页数 //alert(scrollable.getPageIndex());//获取当前所在分页 //alert(scrollable.getRoot().html());//获取滚动项的上一级节点(id=thumbs) //alert(scrollable.getSize()); //alert(scrollable.getVisibleItems().length);//获取当前可见滚动项数量 scrollable.next();//如果有下一个滚动项,则跳转到下一个滚动项 scrollable.prev(3000,function(){return true});//跳转到前一滚动项 //var seekTo= scrollable.click(0).seekTo(2,1000,function(){ //alert(this.getIndex()); //}); //scrollable.move(2); //scrollable.prevPage();//跳转到前一页 //scrollable.nextPage();//跳转到下一页 //scrollable.setPage(1);//跳转到下一页 //scrollable.begin();//跳转到第一个滚动项 //scrollable.end();//跳转到最后一个滚动项 scrollable.click(3);//使第四个滚动项处于选中状态 scrollable.onBeforeSeek(function(){ alert("you click the "+this.getIndex()+"st scrollable item!"); }); $("#remove").click(function(){ scrollable.getItems().filter(":last").remove();//删除最后一个滚动项 scrollable.reload().prev();//自动更新相关配置信息,并跳转到被删除滚动项的前一项 }); 以下是scrollable对象的方法说明描述:
最后,给出本scrollable系列的完整示例代码: 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script src="http://cdn.jquerytools.org/1.0.2/jquery.tools.min.js"></script> <script src="http://static.flowplayer.org/js/jquery.mousewheel.js" ></script> <link rel="stylesheet" type="text/css" href="http://static.flowplayer.org/tools/css/scrollable-navig.css" /> <style><!-- div.scrollable { position:relative; overflow:hidden; width: 646px; height:300px; } #thumbs { position:absolute; width:20000em; clear:both; border:1px solid #222; } a.prev, a.next { margin-top:118px; } #thumbs div { float:left; width:214px; height:300px; background:#333 url(/upload/20090906120115441.png) repeat-x 0 146px; color:#fff; border-left:1px solid #333; cursor:pointer; } #thumbs div.hover { background-color:#444; } #thumbs div.active { background-color:#066; cursor:default; } #thumbs h3, #thumbs p, #thumbs span { margin:13px; font-family:"bitstream vera sans"; font-size:13px; color:#fff; } #thumbs h3 em { font-style:normal; color:yellow; } --></style><style>div.scrollable { position:relative; overflow:hidden; width: 646px; height:300px; } #thumbs { position:absolute; width:20000em; clear:both; border:1px solid #222; } a.prev, a.next { margin-top:118px; } #thumbs div { float:left; width:214px; height:300px; background:#333 url(/upload/20090906120115441.png) repeat-x 0 146px; color:#fff; border-left:1px solid #333; cursor:pointer; } #thumbs div.hover { background-color:#444; } #thumbs div.active { background-color:#066; cursor:default; } #thumbs h3, #thumbs p, #thumbs span { margin:13px; font-family:"bitstream vera sans"; font-size:13px; color:#fff; } #thumbs h3 em { font-style:normal; color:yellow; }</style> <!-- navigator --> <div class="navi"></div> <!-- prev link --> <a class="prev"></a> <!-- root element for scrollable --> <div class="scrollable"> <div id="thumbs"> <div> <img src="http://files.jb51.net/upload/20090906120116994.jpg" /> <h3><em>1. </em>An example title</h3> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et felis eget tellus pharetra porttitor. Praesent dui arcu, egestas quis, adipiscing a. </p> <span class="blue">60 sec</span> </div> <div> <img src="http://files.jb51.net/upload/20090906120117587.jpg" /> <h3><em>2. </em>An example title</h3> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et felis eget tellus pharetra porttitor. Praesent dui arcu, egestas quis, adipiscing a. </p> <span class="blue">80 sec</span> </div> <div> <img src="http://files.jb51.net/upload/20090906120117884.jpg" /> <h3><em>3. </em>An example title</h3> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et felis eget tellus pharetra porttitor. Praesent dui arcu, egestas quis, adipiscing a. </p> <span class="blue">100 sec</span> </div> <div> <img src="http://files.jb51.net/upload/20090906120117490.jpg" /> <h3><em>4. </em>An example title</h3> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et felis eget tellus pharetra porttitor. Praesent dui arcu, egestas quis, adipiscing a. </p> <span class="blue">120 sec</span> </div> <div> <img src="http://files.jb51.net/upload/20090906120118968.jpg" /> <h3><em>5. </em>An example title</h3> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et felis eget tellus pharetra porttitor. Praesent dui arcu, egestas quis, adipiscing a. </p> <span class="blue">140 sec</span> </div> </div> </div> <!-- next link --> <a class="next"></a> <!-- let rest of the page float normally --> <br clear="all" /> <div> <input type="button" value="remove" id="remove"/> </div> <script type="text/javascript"><!-- $(function() { $("div.scrollable").scrollable({ size: 3, vertical:false, //clickable:false, loop:true,//设置是否自动跳转(根据间隔时间) //interval: 1000,//设置间歇时间间隔 //speed:2000, items: #thumbs, //prev:.prev,//跳转到上一项 //next:.next//跳转到下一项 prevPage:.prev,//跳转到上一页 nextPage:.next,//跳转到下一页 hoverClass: hover, easing:linear }); var scrollable=$("div.scrollable").scrollable(); //alert(scrollable.getConf().prev);//获取配置对象中的prev属性 scrollable.getConf().speed=200;//设置配置对象的speed属性 //alert(scrollable.getIndex());//获取当前滚动项的索引 //alert(scrollable.getItems().length);//获取当前滚动项的数量 //alert(scrollable.getItemWrap().html());//获取包含滚动项的节点(class=scrollable),并将所有滚动项显示出来 //alert(scrollable.getPageAmount());//获取当前滚动栏分页数 //alert(scrollable.getPageIndex());//获取当前所在分页 //alert(scrollable.getRoot().html());//获取滚动项的上一级节点(id=thumbs) //alert(scrollable.getSize()); //alert(scrollable.getVisibleItems().length);//获取当前可见滚动项数量 scrollable.next();//如果有下一个滚动项,则跳转到下一个滚动项 scrollable.prev(3000,function(){return true});//跳转到前一滚动项 //var seekTo= scrollable.click(0).seekTo(2,1000,function(){ //alert(this.getIndex()); //}); //scrollable.move(2); //scrollable.prevPage();//跳转到前一页 //scrollable.nextPage();//跳转到下一页 //scrollable.setPage(1);//跳转到下一页 //scrollable.begin();//跳转到第一个滚动项 //scrollable.end();//跳转到最后一个滚动项 scrollable.click(3);//使第四个滚动项处于选中状态 scrollable.onBeforeSeek(function(){ alert("you click the "+this.getIndex()+"st scrollable item!"); }); $("#remove").click(function(){ scrollable.getItems().filter(":last").remove();//删除最后一个滚动项 scrollable.reload().prev();//自动更新相关配置信息,并跳转到被删除滚动项的前一项 }); }); // --></script> ![]() |