Skip to content

Instantly share code, notes, and snippets.

@tsmd
Created January 10, 2013 04:03
Show Gist options
  • Save tsmd/4499349 to your computer and use it in GitHub Desktop.
Save tsmd/4499349 to your computer and use it in GitHub Desktop.
$('#hoge').haneru('+=200', '+=100', 100, 500)
$.fn.haneru = function (x, y, takasa, duration) {
var self = this;
return self.queue(function () {
var offset = self.offset();
var step = function (now, fx) {
if (fx.prop !== 'y') return;
self.css({
left:fx.elem.x,
top:fx.elem.y - Math.sin(Math.PI * fx.pos) * takasa
});
};
$({
x:offset.left - parseInt(self.css('margin-left')),
y:offset.top - parseInt(self.css('margin-top'))
})
.animate({ x:x, y:y }, {
duration:duration,
easing:'linear',
complete:$.proxy(self, 'dequeue'),
step:step
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment