forked from ramugoud/cswebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
197 lines (135 loc) · 5.67 KB
/
index.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
(function($) {
$.fn.foldscroll = function( options ) {
// Constants
var PI = Math.PI;
var HALF_PI = PI / 2;
// Merge options & defaults
var opts = $.extend( {}, $.fn.foldscroll.defaults, options );
// Transformation template
var rot = 'perspective(' + opts.perspective + 'px) rotateX(θrad)';
// Main plugin loop
return this.each( function () {
var $this = $( this );
var $kids = $this.children();
var $item;
var $shading;
if ( opts.shading ) {
// Create an overlay for shading
$shading = $( '<span class="shading"/>' ).css({
background: opts.shading,
position: 'absolute',
opacity: 0.0,
height: '100%',
width: '100%',
left: 0,
top: 0
});
// Add shading to each child
$kids.each( function() {
$item = $(this);
$item.css( prefix({
'backface-visibility': 'hidden',
'transform-style': 'preserve-3d' // Fixes perspective in FF 10+
}));
// Make sure shading isn't already applied
if ( !$item.data( '_shading' ) ) {
$shading = $shading.clone();
// Prepare element
$item.css( 'position', 'relative' );
$item.data( '_shading', $shading );
$item.append( $shading );
}
});
}
// Prepare container
$this.css( prefix({ 'backface-visibility': 'hidden' }));
// $this.css({ overflow: 'scroll' }); ----THIS LINE HAS BEEN INTENTIONALLY REMOVED DO NOT UNDERANY CIRCUMSTANCES UNCOMMENT THIS LINE OR TWO PUPPIES WILL DIE EVERY SECOND.
$this.on( 'scroll', function() {
// Store scroll amount
var st = $this.scrollTop();
// Store viewport properties
var vt = $this.offset().top - st;
var vh = $this.outerHeight();
var vb = vt + vh;
// Compute margin
var m = parseFloat( opts.margin );
m = m <= 1.0 ? Math.min( m, 0.5 ) : m / vh;
// Update children
$kids.each( function( index, el ) {
$item = $(this);
// Remove current transform
$item.css( prefix({ transform: 'none' }) );
// Cache shading element if it exists
$shading = $item.find( '.shading' ).hide();
// Store element properties
var et = $item.offset().top - st;
var eh = Math.max( m * vh, $item.outerHeight() );
var eb = et + eh;
// Highest start value
var a = Math.max( vt, et );
// Lowest end value
var b = Math.min( vb, eb );
// Do line segments overlap?
var show = a < b;
// If there's overlap
if ( show ) {
// compute overlap
var o = b - a;
var p = o / vh;
if ( p < m ) {
// normalise
p = p / m;
// direction
var d = et < vt ? 1 : -1;
// rotation
var t = ( 1 - p ) * HALF_PI * d;
// Contrain rotation
if ( Math.abs(t) <= HALF_PI ) {
// Apply rotation
$item.css( prefix({
'transform-origin': '50%' + ( et < vt ? '100%' : '0%' ),
'transform': rot.replace( 'θ', t )
}));
// Update shading overlay
if ( opts.shading )
$shading.css( 'opacity', 1.0 - p ).show();
} else {
show = false;
}
}
}
// Hide items outside of the viewport
$item.css( 'visibility', show ? 'visible' : 'hidden' );
});
});
// Set initial state
$this.trigger( 'scroll' );
});
};
// CSS3 vendor prefix helper
function prefix( obj ) {
var key, val;
for ( key in obj ) {
val = obj[ key ];
obj[ '-webkit-' + key ] = val;
obj[ '-moz-' + key ] = val;
obj[ '-ms-' + key ] = val;
obj[ '-o-' + key ] = val;
}
return obj;
}
// Default options
$.fn.foldscroll.defaults = {
// Perspective to apply to rotating elements
perspective: 400,
// Default shading to apply (null => no shading)
shading: 'rgba(0,0,0,0.2)',
// Area of rotation (fraction or pixel value)
margin: 0.2
};
})( jQuery );
$( '.quotes' ).foldscroll({
perspective: 500,
margin: '220px'
});
function abc(){ document.getElementById('loader').style.display = 'none'; };