javascript - How can i use requestAnimationFrame instead of translate3d? -
due behaviour of browser translate3d renders vector elements textures need use simple 2d translate, means performance harmed. tried find solution , requestanimationframe
came up, can't figure out how use in case:
$document.bind(events['move'], function(e) { $('.slide-panel.shown').find('.close-panel').trigger('click'); var valuex = gettransform($elem,'posx'), valuey = gettransform($elem,'posy'), zoom = gettransform($elem,'zoom'), translatex, translatey; if (is_touch_device()) { translatex = valuex + (e.originalevent.touches[0].pagex - mouse.x); translatey = valuey + (e.originalevent.touches[0].pagey - mouse.y); } else { translatex = valuex + (e.pagex - mouse.x); translatey = valuey + (e.pagey - mouse.y); } $elem.css({ 'transform': 'translate3d(' + translatex +'px, ' + translatey +'px, 0) scale('+zoom+')', '-webkit-transform': 'translate3d(' + translatex +'px, ' + translatey +'px, 0) scale('+zoom+')', '-moz-transform': 'translate3d(' + translatex +'px, ' + translatey +'px, 0) scale('+zoom+')' }); console.log($elem.css('transform')) mouse.update(e); e.preventdefault(); });
there lot involved, part of drag , drop code uses translate3d move element around, need somehow rid of translate3d , use translate within animation frame
i don't think requestanimationframe going solve performance problems here.
you're using event handler searching elements on every 'tick'. cache elements request dom:
(function () { var $closeelement = $('.slide-panel.shown').find('.close-panel'); $document.bind(events['move'], function(e) { $closeelement.trigger('click'); // rest of animation code. }); }());
how many events fired when you're moving?
if there lot of events try throttling animation. remy sharp has great article on how this: https://remysharp.com/2010/07/21/throttling-function-calls
Comments
Post a Comment