黑松山资源网 Design By www.paidiu.com
本文介绍了的4种实现遮罩层镂空的方法,分享给大家,也给自己留个笔记,具体如下:
先看看效果
【 方法一:截图模拟实现 】
原理:先截一张相同位置的图片,创建一个遮罩层,然后把图片定位在相应的位置上。
优点:原理简单;兼容性好,可以兼容到IE6、IE7;可以同时实现镂空多个。
缺点:此方法只适合静止页面,不适合可以滚动的页面。也不适合页面内容会发生变换的页面。
代码如下:
<div class="class1"> <img src="images/000.jpg" alt=""/> </div> .class1{ position: absolute; width:100%; height:100%; top: 0; left: 0; background-color: #000; opacity: 0.6; filter:alpha(opacity=60); } .class1 img{ position: absolute; top:260px; left: 208px; }
【 方法二:CSS3阴影属性实现 】
原理:利用CSS3的阴影属性。
优点:实现方便;适合任何页面,不会受页面的限制。
缺点:兼容不太好,只能兼容到IE9。
代码如下:
<div class="class2"></div> .class2{ position: absolute; width:170px; height:190px; top: 260px; left: 208px; box-shadow: rgba(0,0,0,.6) 0 0 0 100vh; }
【方法三:CSS边框属性实现 】
原理:利用边框属性。先将一个空盒子定位在目标区域,然后在其四周用边框填充。
优点:实现方便,兼容性好,可以兼容到IE6、IE7;适合任何页面,不会受页面的限制。
缺点:要做兼容实现过程则相对复杂。
代码如下:
<div class="class3"></div> .class3{ position: absolute; width:170px; height:190px; top: 0; left: 0; border-left-width:208px; border-left-style: solid; border-left-color:rgba(0,0,0,.6); border-right-width:970px; border-right-style: solid; border-right-color:rgba(0,0,0,.6); border-top-width:260px; border-top-style: solid; border-top-color:rgba(0,0,0,.6); border-bottom-width:253px; border-bottom-style: solid; border-bottom-color:rgba(0,0,0,.6); }
【 方法四:SVG或者canvas 】
原理:利用SVG或者canvas的绘图功能。
优点:可以同时镂空多个。
缺点:兼容性不好,实现过程相对复杂。
我以SVG为例,代码如下:
<svg style="position: absolute;" width="1366" height="700"> <defs> <mask id="myMask"> <rect x="0" y="0" width="100%" height="100%" style="stroke:none; fill: #ccc"></rect> <rect id="circle1" width="170" height="190" x='208' y="260" style="fill: #000" /> </mask> </defs> <rect x="0" y="0" width="100%" height="100%" style="stroke: none; fill: rgba(0, 0, 0, 0.6); mask: url(#myMask)"></rect> </svg>
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《神话时代:重述版》评测:粉丝们的朝花夕拾
- 战锤40K星际战士2先锋职业介绍|先锋职业技能效果一览
- 战锤40K星际战士2重装职业介绍|重装职业技能效果一览
- 交错战线能源发电站推荐角色一览
- 阿波罗乐神之音《第4集出埃及记》[WAV+CUE]
- JohnWrightTrio-SouthSideSoul-1960-2024(24-192)
- AnthonyBruno-Cefalu(2024)[24-96]
- 《地狱潜者2》玩家人数飙升:终于不再削弱玩家了
- 黑神话引力!外媒分享孙悟空英文书籍:美生中国人等
- 《荒野大镖客》PC版曝光!《GTA6》疑似也有PC版
- 林宥嘉.2008-神秘嘉宾(引进版)【华研国际】【WAV+CUE】
- 徐小凤.1997-金曲精选(康艺经典珍藏系列)【康艺成音】【WAV+CUE】
- 群星.1994-非常精丫宝丽金】【WAV+CUE】
- 《赛马娘 热血喧闹大感谢祭!》评测:现代复古派对
- 《星球大战:亡命之徒》评测:还是看看远方的光剑吧