毛玻璃效果css可以有很多种方法实现,但基本上实现毛玻璃效果兼容性都不太好,今天我们就来实现一个兼容各种浏览器的毛玻璃效果。
<html> <head> <meta charset="UTF-8"> <link rel="apple-touch-icon" type="image/png" href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png"> <meta name="apple-mobile-web-app-title" content="CodePen"> <link rel="shortcut icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico"> <link rel="mask-icon" type="image/x-icon" href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-8f3771b1072e3c38bd662872f6b673a722f4b3ca2421637d5596661b4e2132cc.svg" color="#111"> <title>css实现毛玻璃效果兼容各种浏览器www.woaidaogu.com</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> body { font-family: "Roboto", sans-serif; height: 150vh; } .bg { position: absolute; top: 0; left: 0; width: 100vw; height: 150vh; background: url("https://static.pexels.com/photos/373934/pexels-photo-373934.jpeg") no-repeat; background-size: cover; display: flex; flex-wrap: wrap; align-content: flex-start; } .bg div { width: 200px; height: 120px; line-height: 120px; margin: 50px; border: 10px solid #ddd; color: #fff; text-align: center; font-size: 28px; } .g-glossy { position: fixed; width: 600px; height: 300px; line-height: 300px; top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%); color: #333; font-size: 30px; text-align: center; background-color: rgba(255, 255, 255, 0.5); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); z-index: 10; } .g-glossy::before { content: unset; } @supports (background: -moz-element(#bg)) { .g-glossy::before { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: -moz-element(#bg) no-repeat; filter: blur(10px); z-index: 5; } } </style> <script> window.console = window.console || function (t) { }; </script> <script> if (document.location.search.match(/type=embed/gi)) { window.parent.postMessage("resize", "*"); } </script> </head> <body translate="no"> <div id="bg"> <div>模拟真实 DOM</div> <div>模拟真实 DOM</div> <div>模拟真实 DOM</div> <div>模拟真实 DOM</div> <div>模拟真实 DOM</div> <div>模拟真实 DOM</div> <div>模拟真实 DOM</div> <div>模拟真实 DOM</div> <div>模拟真实 DOM</div> </div> <div>frosted glass effect </div> <div style="background-position: -374.5px 69px;"></div> <script src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-1b93190375e9ccc259df3a57c1abc0e64599724ae30d7ea4c6877eb615f89387.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script id="rendered-js"> $(function () { let blur = $('.g-glossy-firefox')[0].style; let offset = $('.g-glossy').eq(0).offset(); function updateBlur() { blur.backgroundPosition = `${-window.scrollX - offset.left}px ` + `${-window.scrollY - offset.top}px`; } document.addEventListener('scroll', updateBlur, false), updateBlur(); }); //# sourceURL=pen.js </script> <div id="xl_chrome_ext_{4DB361DE-01F7-4376-B494-639E489D19ED}" style="display: none;"> <div></div> <a id="xl_chrome_ext_download" href="javascript:;">下载视频</a> <a id="xl_chrome_ext_close" href="javascript:;"></a> </div> </body> </html>
通过以上内容我们知道了css如何实现毛玻璃效果?感谢您访问“我爱捣鼓(www.woaidaogu.com)”网站的内容,希望对大家有所帮助!引用本文内容时,请注明出处!谢谢合作!