简体   繁体   English

css 过滤器值不会立即应用于 safari 但 chrome

[英]css filter value does not apply instantly in safari but chrome

while dragging input range, brightness value (also css property) is updating but image is not effected instantly in safari. (but in chrome it works well)拖动输入范围时,亮度值(也是 css 属性)正在更新,但图像不会立即在 safari 中生效。(但在 chrome 中效果很好)

how to update changes apply while dragging?如何在拖动时更新应用更改?

var app = Vue.createApp({
   data() {
   return {
    brightness: 1
    }
  },
  computed:{
    imgStyle(){
        return {
        '-webkit-filter': `brightness(${this.brightness})` 
      }
  }
  }
});

var vm = app.mount("#app"); 



<div id="app">
      <img src="https://images.pexels.com/photos/45201/kitty-cat-kitten-pet-45201.jpeg?" width="150"
      :style="imgStyle">
      
   <input type="range" min="0" max="2" step="0.1" v-model="brightness"/>
      <span>  {{brightness}}  </span>
 </div>

https://jsfiddle.net/akin/b8ey1twp/16/ https://jsfiddle.net/akin/b8ey1twp/16/

This answers had a hack that "automagically" fixed this weird behaviour from Safari. This answers had a hack that "automagically" fixed this weird behavior from Safari.

You have to add a class with translate3d(0) or translateZ(0) which forces your browser to use GPU to recalculate changes made to this element and then reacts on them, this seems to overcome this issue on Safari without making any visual difference to your UI.您必须添加带有translate3d(0)translateZ(0)的 class,这会强制您的浏览器使用 GPU 来重新计算对此元素所做的更改,然后对它们做出反应,这似乎可以解决 Safari 上的这个问题,而不会造成任何视觉差异你的用户界面。

 var app = Vue.createApp({ data() { return { brightness: 1 } }, computed: { imgStyle() { return { '-webkit-filter': `brightness(${this.brightness})` } } } }); var vm = app.mount("#app");
 <script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script> <style>.cat-img { transform: translateZ(0); ; } </style> <div id="app"> <img src="https://images.pexels.com/photos/45201/kitty-cat-kitten-pet-45201.jpeg?" width="150":style="imgStyle" class="cat-img"> <input type="range" min="0" max="2" step="0.1" v-model="brightness" /> <span> {{brightness}} </span> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM