CSS/蒙层:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
无编辑摘要
 
(未显示同一用户的14个中间版本)
第21行: 第21行:


== 相关属性 ==
== 相关属性 ==
{| class="wikitable"
=== pointer-events ===
|-
鼠标事件穿透。
| pointer-events || 示例 || 示例
 
|-
在镂空事件穿透场景下,要在遮罩层阻止事件穿透并在镂空区域允许事件穿透,所以需要注意的是不能直接对遮罩层设置 <code>pointer-events:none</code> 属性,而是通过 <code>JavaScript</code> 监听鼠标移动,在镂空区域时设置 <code>pointer-events:none</code>,离开镂空区域设置 <code>pointer-events:auto</code>。
| 示例 || 示例 || 示例
 
|-
{{Warning|当遮罩层被设置 <code>pointer-events:none</code> 时不能有效监听 <code>mosuemove</code>,所以监听 <code>mosuemove</code> 事件需要在遮罩层的上一层 DOM 进行。}}
| 示例 || 示例 || 示例
 
|}
另外,对于 <code>outline</code>、<code>box-shadow</code> 等属于 <code>css</code> 的视觉效果,所以可以直接穿透事件。
 
== 遮罩层 ==
== 遮罩层 ==
<syntaxhighlight lang="css">
<syntaxhighlight lang="css">
第42行: 第43行:
== 镂空 ==
== 镂空 ==
=== 截图模拟实现 ===
=== 截图模拟实现 ===
=== DIV 拼接镂空法 ===
截取一张镂空位置的图片,创建遮罩层,将图片定位在遮罩层上面。
<html><iframe width="100%" height="300" src="//kangkk.com/htdocs/date/2020/截图模拟实现镂空/iframe.html" frameborder="0"></iframe></html>
 
缺点:
* 适合静态不滚动的页面。
优点:
* 兼容 IE6 以上。
 
=== div拼接镂空法 ===
用多个 div 拼接遮罩层。
用多个 div 拼接遮罩层。


<html><iframe width="100%" height="300" src="//www.kangjian.life/date/2020/div拼接镂空方法/iframe.html" frameborder="0"></iframe></html>
<html><iframe width="100%" height="300" src="//kangkk.com/htdocs/date/2020/div拼接镂空方法/iframe.html" frameborder="0"></iframe></html>


缺点:
缺点:
第58行: 第67行:
width="100%"
width="100%"
height="300"
height="300"
src="//www.kangjian.life/date/2020/border边距镂空方法/iframe.html"
src="//kangkk.com/htdocs/date/2020/border边距镂空方法/iframe.html"
frameborder="0"></iframe></html>
frameborder="0"></iframe></html>


第65行: 第74行:
* 矩形镂空
* 矩形镂空
优点:
优点:
* 理论兼容 IE7 以上


==== 事件穿透 ====
==== 事件穿透 ====
第71行: 第81行:
width="100%"
width="100%"
height="300"
height="300"
src="//www.kangjian.life/date/2020/border镂空穿透事件方法/iframe.html"
src="//kangkk.com/htdocs/date/2020/border镂空穿透事件方法/iframe.html"
frameborder="0"></iframe></html>
frameborder="0"></iframe></html>


第79行: 第89行:
width="100%"
width="100%"
height="300"
height="300"
src="//www.kangjian.life/date/2020/outline属性镂空方法/iframe.html"
src="//kangkk.com/htdocs/date/2020/outline属性镂空方法/iframe.html"
frameborder="0"></iframe></html>
frameborder="0"></iframe></html>


第87行: 第97行:
width="100%"
width="100%"
height="300"
height="300"
src="//www.kangjian.life/date/2020/outline镂空穿透事件方法/iframe.html"
src="//kangkk.com/htdocs/date/2020/outline镂空穿透事件方法/iframe.html"
frameborder="0"></iframe></html>
frameborder="0"></iframe></html>


第95行: 第105行:
width="100%"
width="100%"
height="300"
height="300"
src="//www.kangjian.life/date/2020/box-shadow属性镂空方法/iframe.html"
src="//kangkk.com/htdocs/date/2020/box-shadow属性镂空方法/iframe.html"
frameborder="0"></iframe></html>
frameborder="0"></iframe></html>


第105行: 第115行:
=== mix-blend-mode属性镂空法 ===
=== mix-blend-mode属性镂空法 ===


<html><iframe width="100%" height="300" src="//www.kangjian.life/date/2020/mix-blend-mode属性镂空方法/iframe.html" frameborder="0"></iframe></html>
<html><iframe width="100%" height="300" src="//kangkk.com/htdocs/date/2020/mix-blend-mode属性镂空方法/iframe.html" frameborder="0"></iframe></html>


==== 事件穿透 ====
==== 事件穿透 ====


<html><iframe width="100%" height="300" src="//www.kangjian.life/date/2020/mix-blend-mode镂空法事件穿透/iframe.html" frameborder="0"></iframe></html>
<html><iframe width="100%" height="300" src="//kangkk.com/htdocs/date/2020/mix-blend-mode镂空法事件穿透/iframe.html" frameborder="0"></iframe></html>


=== canvas镂空方法 ===
=== canvas镂空方法 ===


<html><iframe width="100%" height="300" src="//www.kangjian.life/date/2020/canvas镂空方法/iframe.html" frameborder="0"></iframe></html>
<html><iframe width="100%" height="300" src="//kangkk.com/htdocs/date/2020/canvas镂空方法/iframe.html" frameborder="0"></iframe></html>


=== svg镂空方法 ===
=== svg镂空方法 ===


<html><iframe width="100%" height="300" src="//www.kangjian.life/date/2020/svg镂空方法/iframe.html" frameborder="0"></iframe></html>
<html><iframe width="100%" height="300" src="//kangkk.com/htdocs/date/2020/svg镂空方法/iframe.html" frameborder="0"></iframe></html>
== 参考 ==
* [https://www.zhangxinxu.com/study/201307/color-insert-background-image.html 张鑫旭:背景色镂空技术之color属性实现颜色可控图标实现实例页面]
* [https://developer.mozilla.org/en-US/docs/Web/CSS/mask-composite#Example mask-composite]