Skip to content

Instantly share code, notes, and snippets.

@msurguy
Created February 9, 2013 02:41
Show Gist options
  • Save msurguy/4743592 to your computer and use it in GitHub Desktop.
Save msurguy/4743592 to your computer and use it in GitHub Desktop.
Backbone PhoneGap animation for elements
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