jquery 上下滾動廣告
更新時間:2009年06月17日 22:32:37 作者:
jquery 上下滾動廣告實現(xiàn)代碼,大家可以自行測試,需要加載jquery類庫
復(fù)制代碼 代碼如下:
(function($){
$.fn.extend({
rollList:function(option){
option=$.extend({
direction:"up",
step:1,
time:23
},option);
var step_coe,scroll_coe,score_coe;
if(option.direction=="up")
{
step_coe=1;
scroll_coe=1;
score_coe=1;
}else
{
step_coe=-1;
scroll_coe=-1;
score_coe=0;
}
return this.each(function(){
var $this=$(this);
var _this=this;
var itemHeight;
var temp=$("<DIV> </DIV>");
$this.css("overflow","hidden").children()
.appendTo(temp);
$this.append(temp.clone(true)).append(temp);
itemHeight=$this.children();
itemHeight=itemHeight.eq(1).offset().top-itemHeight.eq(0).offset().top;
while($this.children(":last").offset().top-$this.offset().top<=$this.height())
$this.append(temp.clone(true));
var roll;
this.scrollTop=itemHeight*(1-score_coe);
roll=function (){
temp=setInterval(function(){
if(_this.scrollTop*scroll_coe>=itemHeight*score_coe)
{
_this.scrollTop=(_this.scrollTop-itemHeight)*scroll_coe;
}
_this.scrollTop+=option.step*step_coe;
},option.time);
}
$this.hover(function(){
clearInterval(temp);
},function(){
roll();
});
roll();
});
}
})
}(jQuery));
調(diào)用如下:
復(fù)制代碼 代碼如下:
$(elem).rollList();
相關(guān)文章
解決jquery的ajax調(diào)取后端數(shù)據(jù)成功卻渲染失敗的問題
今天小編就為大家分享一篇解決jquery的ajax調(diào)取后端數(shù)據(jù)成功卻渲染失敗的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
jquery調(diào)取json數(shù)據(jù)實現(xiàn)省市級聯(lián)的方法
這篇文章主要介紹了jquery調(diào)取json數(shù)據(jù)實現(xiàn)省市級聯(lián)的方法,可實現(xiàn)讀取json數(shù)據(jù)綁定到下拉菜單的功能,非常具有實用價值,需要的朋友可以參考下2015-01-01
jQuery實現(xiàn)的調(diào)整表格行tr上下順序
表格元素是大家比較常用的元素,有時候表格中的行需要調(diào)整順序,下面通過代碼實例介紹一下如何利用jquery實現(xiàn)此功能2016-01-01

