UNPKG

5.09 kBJavaScriptView Raw
1(function ($) {
2 // Image transition function
3 Materialize.fadeInImage = function(selectorOrEl) {
4 var element;
5 if (typeof(selectorOrEl) === 'string') {
6 element = $(selectorOrEl);
7 } else if (typeof(selectorOrEl) === 'object') {
8 element = selectorOrEl;
9 } else {
10 return;
11 }
12 element.css({opacity: 0});
13 $(element).velocity({opacity: 1}, {
14 duration: 650,
15 queue: false,
16 easing: 'easeOutSine'
17 });
18 $(element).velocity({opacity: 1}, {
19 duration: 1300,
20 queue: false,
21 easing: 'swing',
22 step: function(now, fx) {
23 fx.start = 100;
24 var grayscale_setting = now/100;
25 var brightness_setting = 150 - (100 - now)/1.75;
26
27 if (brightness_setting < 100) {
28 brightness_setting = 100;
29 }
30 if (now >= 0) {
31 $(this).css({
32 "-webkit-filter": "grayscale("+grayscale_setting+")" + "brightness("+brightness_setting+"%)",
33 "filter": "grayscale("+grayscale_setting+")" + "brightness("+brightness_setting+"%)"
34 });
35 }
36 }
37 });
38 };
39
40 // Horizontal staggered list
41 Materialize.showStaggeredList = function(selectorOrEl) {
42 var element;
43 if (typeof(selectorOrEl) === 'string') {
44 element = $(selectorOrEl);
45 } else if (typeof(selectorOrEl) === 'object') {
46 element = selectorOrEl;
47 } else {
48 return;
49 }
50 var time = 0;
51 element.find('li').velocity(
52 { translateX: "-100px"},
53 { duration: 0 });
54
55 element.find('li').each(function() {
56 $(this).velocity(
57 { opacity: "1", translateX: "0"},
58 { duration: 800, delay: time, easing: [60, 10] });
59 time += 120;
60 });
61 };
62
63
64 $(document).ready(function() {
65 // Hardcoded .staggered-list scrollFire
66 // var staggeredListOptions = [];
67 // $('ul.staggered-list').each(function (i) {
68
69 // var label = 'scrollFire-' + i;
70 // $(this).addClass(label);
71 // staggeredListOptions.push(
72 // {selector: 'ul.staggered-list.' + label,
73 // offset: 200,
74 // callback: 'showStaggeredList("ul.staggered-list.' + label + '")'});
75 // });
76 // scrollFire(staggeredListOptions);
77
78 // HammerJS, Swipe navigation
79
80 // Touch Event
81 var swipeLeft = false;
82 var swipeRight = false;
83
84
85 // Dismissible Collections
86 $('.dismissable').each(function() {
87 $(this).hammer({
88 prevent_default: false
89 }).bind('pan', function(e) {
90 if (e.gesture.pointerType === "touch") {
91 var $this = $(this);
92 var direction = e.gesture.direction;
93 var x = e.gesture.deltaX;
94 var velocityX = e.gesture.velocityX;
95
96 $this.velocity({ translateX: x
97 }, {duration: 50, queue: false, easing: 'easeOutQuad'});
98
99 // Swipe Left
100 if (direction === 4 && (x > ($this.innerWidth() / 2) || velocityX < -0.75)) {
101 swipeLeft = true;
102 }
103
104 // Swipe Right
105 if (direction === 2 && (x < (-1 * $this.innerWidth() / 2) || velocityX > 0.75)) {
106 swipeRight = true;
107 }
108 }
109 }).bind('panend', function(e) {
110 // Reset if collection is moved back into original position
111 if (Math.abs(e.gesture.deltaX) < ($(this).innerWidth() / 2)) {
112 swipeRight = false;
113 swipeLeft = false;
114 }
115
116 if (e.gesture.pointerType === "touch") {
117 var $this = $(this);
118 if (swipeLeft || swipeRight) {
119 var fullWidth;
120 if (swipeLeft) { fullWidth = $this.innerWidth(); }
121 else { fullWidth = -1 * $this.innerWidth(); }
122
123 $this.velocity({ translateX: fullWidth,
124 }, {duration: 100, queue: false, easing: 'easeOutQuad', complete:
125 function() {
126 $this.css('border', 'none');
127 $this.velocity({ height: 0, padding: 0,
128 }, {duration: 200, queue: false, easing: 'easeOutQuad', complete:
129 function() { $this.remove(); }
130 });
131 }
132 });
133 }
134 else {
135 $this.velocity({ translateX: 0,
136 }, {duration: 100, queue: false, easing: 'easeOutQuad'});
137 }
138 swipeLeft = false;
139 swipeRight = false;
140 }
141 });
142
143 });
144
145
146 // time = 0
147 // // Vertical Staggered list
148 // $('ul.staggered-list.vertical li').velocity(
149 // { translateY: "100px"},
150 // { duration: 0 });
151
152 // $('ul.staggered-list.vertical li').each(function() {
153 // $(this).velocity(
154 // { opacity: "1", translateY: "0"},
155 // { duration: 800, delay: time, easing: [60, 25] });
156 // time += 120;
157 // });
158
159 // // Fade in and Scale
160 // $('.fade-in.scale').velocity(
161 // { scaleX: .4, scaleY: .4, translateX: -600},
162 // { duration: 0});
163 // $('.fade-in').each(function() {
164 // $(this).velocity(
165 // { opacity: "1", scaleX: 1, scaleY: 1, translateX: 0},
166 // { duration: 800, easing: [60, 10] });
167 // });
168 });
169}( jQuery ));