forked from benbyford/stopmotion-lite.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopmotion-lite_1.1.js
87 lines (70 loc) · 1.95 KB
/
stopmotion-lite_1.1.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
/*!
* stopmotion-lite.js
* by Ben Byford
*
* Examples and documentation at: http://www.benbyford.com/
* Version: 1.1 (29-MAY-2011)
* Licensed under Creative Commons - Attribution 3.0 Unported (CC BY 3.0).
* http://creativecommons.org/licenses/by/3.0/
* Requires: jQuery v1.2 or later
*/
function stopmotion(divID, animationSpeed, pauseButton) {
// defaults
divID = typeof(divID) != 'undefined' ? divID : slideImages;
animationSpeed = typeof(animationSpeed) != 'undefined' ? animationSpeed : '100';
pauseButton = typeof(pauseButton) != 'undefined' ? pauseButton : '1';
// setup play_pause
if(pauseButton == 1){
$(divID).parent().prepend('<div id="playPause"></div>');
}
// setup classes
$(divID).children().css('position','absolute');
$(divID).find(':first-child').addClass('slideOn first');
// get number of imgs
$imgNum = $(divID).children().length;
$i = '0';
// trigger on window loaded
$(window).load(
function(){
$a = '0';
$pause = '0';
// play_pause button
$('#playPause').css('display', 'block').bind('click', function(){
if($a == '0'){
$(this).css('background-position','0px -20px');
$a = '1';
$pause = '1';
}else{
$(this).css('background-position','0px 0px');
$a = '0';
$pause = '0'
timer1();
}
})
$(divID).animate({ opacity: 1 }, 500, timerLoading)
// animate div
function fadeSlides(){
$('.slideOn').css('display','none').css('z-index','0').removeClass('slideOn').next().addClass('slideOn').css('z-index',$imgNum).css('display','block');
if($i == $imgNum){
$i = '1';
$('.first').addClass('slideOn');
}else{
$i++;
}
timer1();
}
// timer
function timer1(){
if($pause == '0'){
var t = setTimeout(fadeSlides,animationSpeed);
}else{
}
}
// remove loading .gif and start animation
function timerLoading(){
$('#loading').fadeOut(500).remove();
timer1();
}
}
);
}