複製程式碼 程式碼如下: jQuery公告文字左右滚动效果-www.jb51.net <br>#scrollText {<br> width: 400px;<br> margin-right: auto;<br> margin-left: auto;<br>}<br><br>var ScrollTime;<br>function ScrollAutoPlay(contID,scrolldir,showwidth,textwidth,steper){<br> var PosInit,currPos;<br> with($('#'+contID)){<br> currPos = parseInt(css('margin-left'));<br> if(scrolldir=='left'){<br> if(currPos<0 && Math.abs(currPos)>textwidth){<br> css('margin-left',showwidth);<br> }<br> else{<br> css('margin-left',currPos-steper);<br> }<br> }<br> else{<br> if(currPos>showwidth){<br> css('margin-left',(0-textwidth));<br> }<br> else{<br> css('margin-left',currPos-steper);<br> }<br> }<br> }<br>} <p>//--------------------------------------------左右滚动效果----------------------------------------------<br>/*<br>AppendToObj: 显示位置(目标对象)<br>ShowHeight: 显示高度<br>ShowWidth: 显示宽度<br>ShowText: 显示信息<br>ScrollDirection: 滚动方向(值:left、right)<br>Steper: 每次移动的间距(单位:px;数值越小,滚动越流畅,建议设置为1px)<br>Interval: 每次执行运动的时间间隔(单位:毫秒;数值越小,运动越快)<br>*/<br>function ScrollText(AppendToObj,ShowHeight,ShowWidth,ShowText,ScrollDirection,Steper,Interval){<br> var TextWidth,PosInit,PosSteper;<br> with(AppendToObj){<br> html('');<br> css('overflow','hidden');<br> css('height',ShowHeight+'px');<br> css('line-height',ShowHeight+'px');<br> css('width',ShowWidth);<br> }<br> if (ScrollDirection=='left'){<br> PosInit = ShowWidth;<br> PosSteper = Steper;<br> }<br> else{<br> PosSteper = 0 - Steper;<br> }<br> if(Steper<1 || Steper>ShowWidth){Steper = 1}//每次移动间距超出限制(单位:px)<br> if(Interval<1){Interval = 10}//每次移动的时间间隔(单位:毫秒)<BR> var Container = $('<div></div>');<br> var ContainerID = 'ContainerTemp';<br> var i = 0;<br> while($('#' ContainerID).length>0){<br> ContainerID = ContainerID '_' i ;<br> i ;<br> }<br> with(Container){<br> attr('id',ContainerID);<br> css('float','left');<br> css('カーソル','デフォルト');<br> appendTo(AppendToObj);<br> html(ShowText);<br> TextWidth = width();<br> if(isNaN(PosInit)){PosInit = 0 - TextWidth; }<br> css('margin-left',PosInit);<br> Mouseover(function(){<br> clearInterval(ScrollTime);<br> });<br> Mouseout(function(){<br> ScrollTime = setInterval("ScrollAutoPlay('" ContainerID "','" ScrollDirection "'," ShowWidth ',' TextWidth "," PosSteper ")",Interval);<br> });<br> }<br> ScrollTime = setInterval("ScrollAutoPlay('" ContainerID "','" ScrollDirection "'," ShowWidth ',' TextWidth "," PosSteper ")",Interval);<br>}<br> <スクリプトタイプ="text/javascript"> $(document).ready(function(e) { ScrollText($('#scrollText'),23,400,'欢迎光临脚本之家!','left',1,20);//滚アニメーション字幕}); <BR>if(document.getElementById('GoogleAD')!=null){<BR> document.getElementById('GoogleAD').innerHTML = '<div class="SearchEngine_AD1">' document.getElementById('GoogleADCode').innerHTML '</div>';<br>}<br>