-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
122 lines (114 loc) · 4.14 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(function($) {
$.fn.textWidth = function(){
var calc = '<span style="display:none">' + $(this).text() + '</span>';
$('body').append(calc);
var width = $('body').find('span:last').width();
$('body').find('span:last').remove();
return width;
};
$.fn.marquee = function(args) {
var that = $(this);
var textWidth = that.textWidth(),
offset = that.width(),
width = offset,
css = {
'text-indent' : that.css('text-indent'),
'overflow' : that.css('overflow'),
'white-space' : that.css('white-space')
},
marqueeCss = {
'text-indent' : width,
'overflow' : 'hidden',
'white-space' : 'nowrap'
},
args = $.extend(true, { count: -1, speed: 1e1, leftToRight: false }, args),
i = 0,
stop = textWidth*-1,
dfd = $.Deferred();
function go() {
if(!that.length) return dfd.reject();
if(width == stop) {
i++;
if(i == args.count) {
that.css(css);
return dfd.resolve();
}
if(args.leftToRight) {
width = textWidth*-1;
} else {
width = offset;
}
}
that.css('text-indent', width + 'px');
if(args.leftToRight) {
width++;
} else {
width--;
}
setTimeout(go, args.speed);
};
if(args.leftToRight) {
width = textWidth*-1;
width++;
stop = offset;
} else {
width--;
}
that.css(marqueeCss);
go();
return dfd.promise();
};
})(jQuery);
$(document).ready(function()
{
$('h1').marquee();
$('h2').marquee({ count: 2 });
$('h3').marquee({ speed: 5 });
$('h4').marquee({ leftToRight: true });
$('h5').marquee({ count: 1, speed: 2 }).done(function() { $('h5').css('color', '#f00'); });
});
/*
$(document).ready(function()
{
for (var i = 0; i < 11; i++)
{
$('body').append("<p style=\"top:"+i*25+"px; width:1000px; white-space:nowrap; overflow:hidden;right:-1000px;position:absolute\">Test</p>");
}
}
);
var time = 0;
var list = new Array();
for (var x = 0; x < 11; x++)
{
list[x] = 0;
}
setInterval(function()
{
time++;
}, 1000
);
setInterval(function()
{
var i = 5;
var index=-1;
for (var diff = 0; diff <= 5; diff++)
{
if (list[i-diff] < time)
{
index = i-diff;
list[index] = time+10;
$('p:nth-child('+(index+1)+')').css('right', '-1000px').text("This is tweet #"+time+".................................................................................................................................................");
break;
}
else if(list[i+diff] < time)
{
index = i+diff;
list[index] = time+10;
$('p:nth-child('+(index+1)+')').css('right', '-1000px').text("This is tweet #" + time+".................................................................................................................................................");
break;
}
}
if(index!=-1)test(index);},1000);
function test(i) {
$('p:nth-child('+(i+1)+')').animate({right:"+="+($(document).width())},10000, "linear", function(){});
}*/