forked from mazedigital/Web-Ticker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.webticker.js
More file actions
145 lines (136 loc) · 5.01 KB
/
jquery.webticker.js
File metadata and controls
145 lines (136 loc) · 5.01 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*!
* webTicker 1.3
* Examples and documentation at:
* http://jonmifsud.com
* 2011 Jonathan Mifsud
* Version: 1.2 (26-JUNE-2011)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires:
* jQuery v1.4.2 or later
*
*/
(function( $ ){
var globalSettings = new Array();
var methods = {
init : function( settings ) { // THIS
settings = jQuery.extend({
travelocity: 0.05,
direction: 1,
moving: true
}, settings);
globalSettings[jQuery(this).attr('id')] = settings;
return this.each(function(){
var $strip = jQuery(this);
$strip.addClass("newsticker")
var stripWidth = 0;
var $mask = $strip.wrap("<div class='mask'></div>");
$mask.after("<span class='tickeroverlay-left'> </span><span class='tickeroverlay-right'> </span>")
var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
$strip.find("li").each(function(i){
stripWidth += jQuery(this, i).outerWidth(true);
});
$strip.width(stripWidth+200);//20 used for ie9 fix
function scrollnews(spazio, tempo){
if (settings.direction == 1)
$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){
$strip.children().last().after($strip.children().first());
var first = $strip.children().first();
var width = first.outerWidth(true);
var defTiming = width/settings.travelocity;
//$strip.css("left", left);
$strip.css("left", '0');
scrollnews(width, defTiming);
});
else
$strip.animate({right: '-='+ spazio}, tempo, "linear", function(){
$strip.children().last().after($strip.children().first());
var first = $strip.children().first();
var width = first.outerWidth(true);
var defTiming = width/settings.travelocity;
//$strip.css("left", left);
$strip.css("right", '0');
scrollnews(width, defTiming);
});
}
var first = $strip.children().first();
var travel = first.outerWidth(true);
var timing = travel/settings.travelocity;
scrollnews(travel, timing);
$strip.hover(function(){
jQuery(this).stop();
},
function(){
if (globalSettings[jQuery(this).attr('id')].moving){
var offset = jQuery(this).offset();
var first = $strip.children().first();
var width = first.outerWidth(true);
var residualSpace;
if (settings.direction == 1) residualSpace = parseInt(jQuery(this).css('left').replace('px',''))+ width;
else residualSpace = parseInt(jQuery(this).css('right').replace('px',''))+ width;
var residualTime = residualSpace/settings.travelocity;
scrollnews(residualSpace, residualTime);
}
});
});
},
stop : function( ) {
if (globalSettings[jQuery(this).attr('id')].moving){
globalSettings[jQuery(this).attr('id')].moving = false;
return this.each(function(){
jQuery(this).stop();
});
}
},
cont : function( ) { // GOOD
if (!(globalSettings[jQuery(this).attr('id')].moving)){
globalSettings[jQuery(this).attr('id')].moving = true;
var settings = globalSettings[jQuery(this).attr('id')];
return this.each(function(){
var $strip = jQuery(this);
function scrollnews(spazio, tempo){
if (settings.direction == 1)
$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){
$strip.children().last().after($strip.children().first());
var first = $strip.children().first();
var width = first.outerWidth(true);
var defTiming = width/settings.travelocity;
//$strip.css("left", left);
$strip.css("left", '0');
scrollnews(width, defTiming);
});
else
$strip.animate({right: '-='+ spazio}, tempo, "linear", function(){
$strip.children().last().after($strip.children().first());
var first = $strip.children().first();
var width = first.outerWidth(true);
var defTiming = width/settings.travelocity;
//$strip.css("left", left);
$strip.css("right", '0');
scrollnews(width, defTiming);
});
}
var offset = jQuery(this).offset();
var first = $strip.children().first();
var width = first.outerWidth(true);
var residualSpace;
if (settings.direction == 1) residualSpace = parseInt(jQuery(this).css('left').replace('px',''))+ width;
else residualSpace = parseInt(jQuery(this).css('right').replace('px',''))+ width;
var residualTime = residualSpace/settings.travelocity;
scrollnews(residualSpace, residualTime);
});
}
}
};
$.fn.webTicker = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.webTicker' );
}
};
})( jQuery );