refactored animation code

This commit is contained in:
Sacha Greif 2013-03-19 10:54:01 +09:00
parent 0ecd6573a2
commit 9b2d06dc88
7 changed files with 28 additions and 49 deletions

View file

@ -12,5 +12,4 @@ router
moment
spiderable
email
profiler
database-forms

View file

@ -829,7 +829,7 @@ body.pageslide-open {
position: relative; }
/* line 7, ../sass/modules/_posts.scss */
.posts .post {
position: absolute;
position: relative;
width: 100%;
/* For modern browsers */
/* For IE 6/7 (trigger hasLayout) */

View file

@ -5,7 +5,7 @@
.posts{
position:relative;
.post{
position:absolute;
position:relative;
width:100%;
@include cf;
&.animate{

View file

@ -60,33 +60,28 @@ Template.post_item.helpers({
});
Template.post_item.rendered = function(){
var self = this;
var rank = self.data._rank;
var $this = $(this.find(".post"));
if(self.data){
var distanceFromTop= 0;
for(var i=1; i<=rank; i++){
distanceFromTop+= $('.post-'+i).height();
}
// if this is the first rendering, just go straight to the correct spot,
// and don't animate our way there.
if (_.isUndefined(self.current_distance)) {
self.current_distance = distanceFromTop;
$this.css("top", self.current_distance + "px");
// otherwise, stay in the old spot, but once the browser has rendered
// us there, animate to a new spot
} else {
$this.css("top", self.current_distance + "px");
Meteor.defer(function() {
self.current_distance = distanceFromTop;
$this.addClass('animate').css("top", self.current_distance + "px");
});
}
// animate post from previous position to new position
var instance = this;
var rank = instance.data._rank;
var $this = $(this.firstNode);
var previousPosition = 0;
var newPosition = 0;
for(var i=1; i<=rank; i++){
newPosition += $('.post-'+i).height();
}
// if element has a currentPosition (i.e. it's not the first ever render)
if(previousPosition = instance.currentPosition){
// calculate difference between old position and new position and send element there
var delta = previousPosition - newPosition;
$this.css("top", delta + "px");
}
Meteor.defer(function() {
instance.currentPosition = newPosition;
// bring element back to its new original position
$this.addClass('animate').css("top", "0px");
});
};
Template.post_item.events = {

View file

@ -55,8 +55,8 @@ Meteor.methods({
});
// permissions for the profiler
Meteor.Profiler.allow = function(userId) {
var user = Meteor.users.findOne(userId);
return user && user.isAdmin;
};
// Meteor.Profiler.allow = function(userId) {
// var user = Meteor.users.findOne(userId);
// return user && user.isAdmin;
// };

View file

@ -3,7 +3,6 @@
"packages": {
"router": {},
"moment": {},
"profiler": {"git": "https://github.com/tmeasday/meteor-profiler.git"},
"database-forms": {}
}
}

View file

@ -2,16 +2,12 @@
"meteor": {
"git": "https://github.com/meteor/meteor.git",
"branch": "master",
"commit": "471f661c5b32bf66746077defbbac8b2b26046c6"
"commit": "f07715dc70de16a7aab84e56ab0c6cbd9c1f9dc6"
},
"dependencies": {
"basePackages": {
"router": {},
"moment": {},
"profiler": {
"git": "https://github.com/tmeasday/meteor-profiler.git",
"branch": "master"
},
"database-forms": {}
},
"packages": {
@ -25,11 +21,6 @@
"tag": "v1.7.0",
"commit": "c64b6ec0e714b9556f4b6643d430b868ba69d3d7"
},
"profiler": {
"git": "https://github.com/tmeasday/meteor-profiler.git",
"branch": "master",
"commit": "25a14a4e94a4748745738031baab1400860eede7"
},
"database-forms": {
"git": "https://github.com/lyudmil/database-forms.git",
"tag": "v0.0.2",
@ -39,11 +30,6 @@
"git": "https://github.com/tmeasday/meteor-page-js-ie-support.git",
"tag": "v1.3.5",
"commit": "b99ed8380aefd10b2afc8f18d9eed4dd0d8ea9cb"
},
"node-modules": {
"git": "https://github.com/possibilities/meteor-node-modules.git",
"tag": "v0.0.5",
"commit": "d502e5091759073a6baed856fadd93012749842d"
}
}
}