javascript - .scroll() 函数在上次更新后在 google chrome 中定位闪烁

标签 javascript jquery css google-chrome scroll

说实话,我有点绝望。

在我的 Google Chrome 浏览器更新之后——我认为是版本 39 到 41——我的一个客户网站在 Chrome 中完全毁容了。

你可以在这里看到: http://prinovis-media-day.com/

如果向下滚动,所有 »parallax« 元素都会闪烁。 我已经在我的 macbook 版本 39 上检查过了——它在版本 39 中绝对没问题。

基本上,我为创建这种效果所做的工作非常简单:

$("window").scroll(function(){

     var move_value = Math.round(scroll_top * 0.3);
     var opacity_value = *some other value*;

     $(".parallax-container__content").css({

        'opacity': opacity_value,
        'padding-top': move_value +'px'

     });

});

有人知道怎么回事吗?在此更新之前,它就像一个魅力...

提前致谢,非常感谢任何答复!

最佳答案

将我的评论作为答案:

You could always cache the $(".parallax-container__content") element in a variable so that it is not retrieving it on every time the scroll event is fired, and that goes for the opacity value too (unless that is dynamically changing depending on scroll_tp. Doing this might cause the script to speed up and help the jank that is happening

If it is still really noticeable, then you could use feature detection to detect if CSS transforms are supported in the browser and user 'transform: translate' instead of changing the 'top' value. If it is not supported, then just revert back to changing the 'top'. Changing the 'top' causes a repaint in the browser while 'translate' does not. This repaint is quite expensive to the browser and can cause jank on certain machines. modernizr.com can help you out with feature detection, but it is potentially overkill for just helping out in the this situation.

看看这个检测是否支持某些样式:http://lea.verou.me/2009/02/check-if-a-css-property-is-supported/

这是最简单的检查方法(记得考虑 vendor 前缀)。

关于javascript - .scroll() 函数在上次更新后在 google chrome 中定位闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29488192/

相关文章:

javascript - 使用 CSS 媒体查询时不打印背景

javascript - 条件点 slider jQuery

javascript - iDangerous Swiper 未检测到滑动

javascript - self.focus() 和 window.focus() 适用于 Safari,但不适用于 IE

javascript - 如何使用下拉列表触发 Jquery 函数?

javascript - 为什么 "opener.$(document).trigger(' 自定义 ')"不起作用?

javascript - 检查一个元素是否具有一个类与另一个类总是返回 true

css - 第一个 child 影响里面的每一个元素

css - 为什么 Mudblazor 组件在没有 css 的情况下出现?

html - 页面即使没有内容也有滚动