admin管理员组文章数量:1277885
This question pertains less to parallax than it does to scroll events. My overriding concern with my project is that the parallax scroll effect is smooth and not jittery.
My question then is, do certain properties animate / scroll better than others? For example does background-position work better than say adjusting margin-top on scroll.
This question pertains less to parallax than it does to scroll events. My overriding concern with my project is that the parallax scroll effect is smooth and not jittery.
My question then is, do certain properties animate / scroll better than others? For example does background-position work better than say adjusting margin-top on scroll.
Share Improve this question asked Jan 18, 2012 at 18:29 Philip McLaughlinPhilip McLaughlin 861 silver badge5 bronze badges1 Answer
Reset to default 11I'm not sure if some properties create less overhead while animating than others but I would be very interested if someone posts some good information on that subject. That being said I do know of a couple things that can help performance.
Setting position : absolute
removes the element from the regular flow of the page and therefore does not require the entire page to be redrawn when it is animated. position : relative
will force a redraw of the whole page since ancestor and descendant elements can be affected.
Also, you can throttle the scroll
event and still achieve 30fps:
var scroll_ok = true;
setInterval(function () {
scroll_ok = true;
}, 33);//33ms is 30fps, you can try changing this to something larger for better performance
$(window).bind('scroll', function () {
if (scroll_ok === true) {
scroll_ok = false;
//now run your code to animate with respect to scroll
}
});
UPDATE :: 2014-08-26
Things have changed since this was originally written. A few quick notes:
Modern browsers now attempt to GPU accelerate the painting of elements given a specific set of properties (
opacity
andtransform
off the top of my head). Using these properties can greatly improve performance over others liketop
/left
(which also require redrawing the page in more instances than using atransform
).will-change
is a new property just being picked up by browsers. You can basically set a list of properties that are likely to change so the browser can optimize the property change ahead of time.requestAnimationFrame
has a robust polyfill and good modern browser support. This is a much better way to smoothly animate elements without creating tons of "chunk" as the browser will render as it can.
本文标签: javascriptjQuery ParallaxScroll Events PerformanceStack Overflow
版权声明:本文标题:javascript - jQuery ParallaxScroll Events Performance - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741301486a2371113.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论