Pressing the button will blur the background, but when transitioning, the edge transition of the div does not work well. This problem occurs in all browsers except Firefox, how do I fix it?
var btn = document.querySelector('button'); var div = document.querySelector('div'); btn.addEventListener('click', function() { div.classList.toggle('blur'); });
body { margin: 0; background: url('https://images.pexels.com/photos/2763927/pexels-photo-2763927.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1')no-repeat; background-size: cover; } div { width: 900px; height: 900px; transition: 1s ease; } .blur { backdrop-filter: blur(20px); transition: 1s ease; }
<body> <div class="cube"></div> <button>BLUR BUTTON</button> </body>
Because the image fills
<body>
, but.blur
in<div>
is only 900x900 pixels.Quick Fix:
Change:
var div = document.querySelector('div');
To:
var div = document.body;
Or: move
background: url(..); background-size: ..
todiv
and get it from there.