简体   繁体   English

使用画布或SVG在整个页面上放置蒙版

[英]Put a mask over a whole page with canvas or SVG

I am trying to make a mask over a whole page. 我试图在整个页面上做一个蒙版。 My solution is to make a transparent png with the shape of the mask and making the borders really big. 我的解决方案是制作具有蒙版形状的透明png,并使边框真正变大。 After that I am putting this over the whole document. 之后,我将其放在整个文档中。

Although I already got the solution, but it looks really dirty to me and is not responsive at all. 尽管我已经有了解决方案,但是它对我来说真的很脏,根本没有响应。

Is there a better solution to do this like with canvas, javascript and SVG? 有没有更好的解决方案,例如使用canvas,javascript和SVG?

.masktest {
  position: fixed;
  z-index: 9999;
  width: 200px;
  height: 200px;
  border: 8000px solid #000;
  left: 50%;
  top: 50%;
  margin-top: -8100px;
  margin-left: -8100px;
  background-image: url('img/masktest.png');
}

Here is the fiddle 这是小提琴

I would make the mask with a pseudo element either :before or :after . 我会用:before:after伪元素制作面具。

 body { margin: 0; } body:before { content: ""; position: fixed; background: rgba(0,0,0,.75) url("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/mozilla.svg") center / cover; width: 100%; height: 100%; } 
 Hello world. 

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

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