100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > html 向上滚动 不间断 JS实现单行文字不间断向上滚动的方法

html 向上滚动 不间断 JS实现单行文字不间断向上滚动的方法

时间:2021-09-24 09:20:52

相关推荐

html 向上滚动 不间断 JS实现单行文字不间断向上滚动的方法

.wrap{padding:10px;border:1px #ccc solid; width:500px;margin:20px auto;}

.roll-wrap{height:130px;overflow:hidden;}

JS文本向上滚动1JS文本向上滚动2JS文本向上滚动3JS文本向上滚动4JS文本向上滚动5JS文本向上滚动6JS文本向上滚动7

function scrollTxt(){

var controls={},

values={},

t1=1000, /*播放动画的时间*/

t2=100, /*播放时间间隔*/

si;

controls.rollWrap=$("#roll-wrap");

controls.rollWrapUl=controls.rollWrap.children();

controls.rollWrapLIs=controls.rollWrapUl.children();

values.liNums=controls.rollWrapLIs.length;

values.liHeight=controls.rollWrapLIs.eq(0).height();

values.ulHeight=controls.rollWrap.height();

this.init=function(){

autoPlay();

pausePlay();

}

/*滚动*/

function play(){

controls.rollWrapUl.animate({"margin-top" : "-"+values.liHeight}, t1, function(){

$(this).css("margin-top" , "0").children().eq(0).appendTo($(this));

});

}

/*自动滚动*/

function autoPlay(){

/*如果所有li标签的高度和大于.roll-wrap的高度则滚动*/

if(values.liHeight*values.liNums > values.ulHeight){

si=setInterval(function(){

play();

},t2);

}

}

/*鼠标经过ul时暂停滚动*/

function pausePlay(){

controls.rollWrapUl.on({

"mouseenter":function(){

clearInterval(si);

},

"mouseleave":function(){

autoPlay();

}

});

}

}

new scrollTxt().init();

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。