-
Notifications
You must be signed in to change notification settings - Fork 6
/
jquery.heapshot.js
168 lines (152 loc) · 5.72 KB
/
jquery.heapshot.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
Copyright 2013 Damien Barrère http://www.crac-design.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function( $ ) {
var options = {
'indexStart' : 100,
'rotation' : 80,
'easing' : function(x, t, b, c, d){return c*t/d + b;}, //See http://dzone.com/snippets/robert-penner-easing-equations
'overflowparents' : true,
'autostart' : true,
'animationdelay' : 1500
};
var _animate = false;
var _interval;
var $heapshot;
var methods = {
init : function( o ) {
$heapshot = $(this);
$heapshot.imagesLoaded(function(){
$.extend(options,o);
if(options.overflowparents===true){
$heapshot.parents().css('overflow','visible');
}
var width=0, height=0;
$heapshot.find('li').each(function(index,elem){
$(elem).css('z-index',options.indexStart+$heapshot.find('li').length-index);
t = Math.floor((Math.random()*10));
$(elem).css('top',t*10);
a = Math.floor((Math.random()*15)+3);
s=Math.floor((Math.random()*2));
if(s==0){
a=-a;
}
$(elem).data('rotation',a);
$(elem).rotate({
angle : a
});
if($(elem).width() > width){
width = $(elem).width();
}
if($(elem).height() > height){
height = $(elem).height();
}
});
$heapshot.css('width',width);
$heapshot.css('height',height);
bindFirst();
});
},
next : function(){
next();
},
previous : function(){
previous();
}
};
next = function(){
$heapshot.find('li img').trigger('click');
};
previous = function(){
};
bindFirst = function(){
if(_animate === true ){
return;
}
bindto = null;
nbli = $heapshot.find('li').length;
$heapshot.find('li').each(function(index,elem){
if(parseInt($(elem).css('z-index')) === options.indexStart+nbli){
bindto = elem;
}
});
$heapshot.find('li').removeClass('current');
$(bindto).addClass('current');
if(options.autostart===true){
clearInterval(_interval);
_interval = setInterval(next, options.animationdelay);
$heapshot.hover(function(){
clearInterval(_interval);
});
$heapshot.on('mouseleave',function(){
_interval = setInterval(next, options.animationdelay);
});
}
$(bindto).find('img').click(function(event){
if(_animate === true ){
event.stopPropagation();
return;
}
_animate = true;
$e = $(this).parent();
from = $e.data('rotation');
to = parseInt(from + options.rotation);
$e.animate({
left : $(this).position().left+$(this).width()+20
}, 1500, function() {
//animation finished
$e.css('z-index',options.indexStart);
$heapshot.find('li').each(function(index,elem){
$(elem).css('z-index',parseInt($(elem).css('z-index'))+1);
});
rfrom = parseInt($(this).getRotateAngle());
rto = parseInt(rfrom - options.rotation);
$e.animate({
left : 0,
}, 1500, function(){
$heapshot.find('li img').unbind();
_animate = false;
bindFirst();
});
$e.rotate({
angle: rfrom,
animateTo : rto,
easing: options.easing,
duration:1500
});
});
$e.rotate({
angle: from,
animateTo : to,
easing: options.easing,
duration:1500
});
});
};
$.fn.heapshot = 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
}
};
})( jQuery );