Skip to content

Commit ad50073

Browse files
author
Michael Bleigh
committed
Adds 'grow' effect, 'swipeleft/right' events
1 parent 17a7b5f commit ad50073

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

demo.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
#cards swipe-able {
2020
padding: 30px 15px;
2121
text-align: center;
22-
box-shadow: 0 3px 3px #aaa;
2322
border: 1px solid #ccc;
2423
border-top: 0;
25-
border-right: 0;
24+
border-left: 0;
2625
border-radius: 2px;
2726
margin-bottom: 10px;
2827
background: white;
@@ -42,6 +41,9 @@
4241
<swipe-able left="rubberband" right="rubberband">
4342
Rubberbands in both directions
4443
</swipe-able>
44+
<swipe-able left="dismiss" right="grow">
45+
Dismiss left, grow right
46+
</swipe-able>
4547
</section>
4648

4749
<p id="message"></p>

swipe-able.html

+31-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
1616
- **dismiss**: the element moves with the user's pointer while swiping, and then
1717
slides away and disappears when the swipe is complete.
18+
- **grow**: the element grows while swiping, then returns to its original size
19+
upon swipe completion.
1820
- **rubberband**: the element "stretches" away from center as the user's pointer
1921
moves, but snaps back to neutral when released.
2022
- **none**: the element stays put, and nothing happens.
@@ -101,6 +103,22 @@
101103
return player;
102104
},
103105
trigger: false
106+
},
107+
grow: {
108+
_calcScale: function(dx) {
109+
return 1.0 + (Math.log(Math.abs(dx)) / 40.0);
110+
},
111+
update: function(el, e) {
112+
_applyTransform(el, "scale(" + _effects.grow._calcScale(e.dx) + ")");
113+
},
114+
finish: function(el, e) {
115+
_applyTransform(el, undefined);
116+
var player = el.animate([
117+
{transform: 'scale(' + _effects.grow._calcScale(e.dx) + ')'},
118+
{transform: 'scale(1.0)'}
119+
], {duration: 200});
120+
},
121+
trigger: true
104122
}
105123
}
106124

@@ -154,7 +172,9 @@
154172
if (Math.abs(e.dx) > this.distanceThreshold) {
155173
var player = this._effect().finish(this, e);
156174
if (this._effect().trigger) {
157-
this.fire("swipe", {effect: this[this.swipeDirection], direction: this.swipeDirection, animation: player});
175+
var detail = {effect: this[this.swipeDirection], direction: this.swipeDirection, animation: player};
176+
this.fire("swipe", detail);
177+
this.fire("swipe" + detail.direction, detail);
158178
}
159179
} else {
160180
this.reset();
@@ -209,6 +229,16 @@
209229
*
210230
* @event swipe
211231
*/
232+
233+
/**
234+
* Same as `swipe`, but only triggered on left swipe.
235+
* @event swipeleft
236+
*/
237+
238+
/**
239+
* Same as `swipe`, but only triggered on right swipe.
240+
* @event swiperight
241+
*/
212242
});
213243
})();
214244
</script>

0 commit comments

Comments
 (0)