-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjquery.stepScroll.js
89 lines (84 loc) · 2.23 KB
/
jquery.stepScroll.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
/**
* jQuery stepScroll 1.0.0
* Copyright (c) 2011 Marcus Campbell
*
* Dual-licensed under the MIT and GPL Version 2 licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($) {
$.fn.stepScroll = function(options) {
var settings = {
scroll: 1500, /* ms */
delay: 2000, /* ms */
opacity: .5 /* 0 - 1 */
};
return this.each(function() {
/**
* Override default settings
*/
if (options) {
$.extend(settings, options);
}
/**
* Apply styles
*/
var total_width = 0;
$("img", this).each(function() {
total_width += $(this).width();
});
total_width = total_width * 2;
$(this).wrap('<div class="stepScroll" \/>');
$(this).parent().css({
overflow: 'hidden',
width: '100%'
});
$(this).css({
margin: 0,
padding: 0,
width: total_width +'px'
});
$('li', this).css({
float: 'left',
listStyle: 'none'
});
/**
* Start scrolling
*/
var looped = false;
_scroll(this);
function _scroll(target) {
$("li img:not(:first)", target).css({
opacity: settings.opacity
});
if (looped) {
var img_width = $("li:eq(1) img", target).width();
$("li:eq(1) img", target).animate({
opacity: 1
}, 500);
}
else {
var img_width = $("li:first img", target).width();
}
$(target).fadeTo(settings.delay, 1).animate({
marginLeft: "-="+ img_width +"px"
}, settings.scroll, null, function() {
$("li img:first", target).css({
opacity: settings.opacity
});
if (looped) {
$("li img:eq(1)", target).css({
opacity: settings.opacity
});
$(target).append($("li:first", target));
$(target).css({
marginLeft: "-"+ img_width +"px"
});
}
looped = true;
_scroll(target);
});
}
});
};
})(jQuery);