文字跑马灯

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//文字跑马灯
var roll = {
init : function(text){
this.text = text;
this.i = 1;
this.time(500);
},
time : function(delay){
var t = this;
window.setInterval(function(){
t.play();
},delay)
},
play : function(){
this.i < 4 ? this.i++ : this.i = 1;
var first = "<span style='color:red;'>" + this.text.split("").slice(0,this.i).join("") + "</span>",
last = this.text.split("").slice(this.i).join("");
$(".roll").html(first + last);
}
};
roll.init("在线留言");
//autoplayDisableOnInteraction: false swiper插件事件不会试autoplay停止