Created
February 9, 2013 02:41
-
-
Save msurguy/4743592 to your computer and use it in GitHub Desktop.
Backbone PhoneGap animation for elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Demo.Views.Page = Backbone.View.extend({ | |
className: "page", | |
initialize: function () { | |
this.render(); | |
}, | |
show: function () { | |
$('.page').css({"position": "absolute"}); | |
var direction_coefficient = this.options.back ? 1 : -1; | |
if ($('.page').length) { | |
var $old = $('.page').not(this.el); | |
// This fix was hard-won - | |
// just doing .css(property, '') doesn't work! | |
$old.get(0).style["margin-left"] = "" | |
$old.get(0).style["-webkit-transform"] = "" | |
this.$el.appendTo('body').hide(); | |
this.$el.show().css( | |
{"margin-left": 320 * direction_coefficient}); | |
this.$el.anim( | |
{translate3d: -320 * direction_coefficient +'px,0,0'}, | |
0.3, 'linear'); | |
$old.anim( | |
{translate3d: -320 * direction_coefficient + 'px,0,0'}, | |
0.3, 'linear', function() { | |
$old.remove(); | |
$('.page').css({"position": "static"}); | |
}); | |
} else { | |
this.$el.appendTo('body').hide(); | |
this.$el.show(); | |
} | |
window.scrollTo(0, 0); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment