CSS遮罩mask

前面的话

  CSS遮罩是2008年4月由苹果公司添加到webkit引擎中的。遮罩提供一种基于像素级别的,可以控制元素透明度的能力,类似于png24位或png32位中的alpha透明通道的效果。本文将详细介绍CSS遮罩mask

概述

  遮罩mask的功能就是使用透明的图片或渐变遮罩元素的背景。于是,遮罩mask与背景background非常类似,除了没有color子属性,背景background剩下的6个子属性,mask都有

  遮罩mask是一个复合属性,包括mask-image、mask-mode、mask-repeat、mask-position、mask-clip、mask-origin、mask-size、mask-composite这8个属性

  [注意]IE浏览器不支持,webkit内核的浏览器(包括chrome、safari、IOS、android)需要添加-webkit-前缀。要特别注意的是,firefox浏览器也支持webkit-mask属性

【mask-image】

  默认值为none,值为透明图片,或透明渐变

【mask-repeat】

  默认值为repeat,可选值与background-repeat相同,详细情况移步至此

【mask-position】

  默认值为0 0,可选值与background-position相同,详细情况移步至此

【mask-clip】

  默认值为border-box,可选值与background-clip相同,详细情况移步至此

【mask-origin】

  默认值为border-box,可选值与background-origin相同,详细情况移步至此

【mask-size】

  默认值为auto,可选值与background-size相同,详细情况移步至此

【mask-mode】

  默认值为match-source,可选值为alpha、luminance、match-source,或者它们的组合

【mask-composite】

  默认值为add,可选值为add、subtract、intersect、exclude

  [注意]只有firefox支持mask-mode和mask-composite

实例

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.wrap{
    position:absolute;
    width: 400px;
    border:1px solid black;
}
#mask{
    height: 300px;
    background:url(http://sandbox.runjs.cn/uploads/rs/142/wat3wtnz/dongzhi.jpg) lightblue;
    -webkit-mask:  url(http://sandbox.runjs.cn/uploads/rs/142/wat3wtnz/mask.png) no-repeat;
    animation: 2s maskPosition infinite alternate ;
}
#mask:hover{
    animation: none;
}
@keyframes maskPosition{
    0%{-webkit-mask-position:0 0;}
    100%{-webkit-mask-position:100% 100%;}
}
</style>
</head>
<body>
<div class="wrap">
    <div id="mask"></div>
</div>
<script>
var oBox = document.getElementById(‘mask‘);
oBox.onmousemove = function(e){
    e = e || event;
    oBox.style.WebkitMaskPosition=(e.clientX-50)+"px "+ (e.clientY-50)+"px";
}
</script>
</body>
</html>

  

时间: 2024-08-02 04:56:25

CSS遮罩mask的相关文章

CSS遮罩——如何在CSS中使用遮罩

Css遮罩是2008年4月由苹果公司添加到webkit引擎中的.遮罩提供一种基于像素级别的,可以控制元素透明度的能力,类似于png24位或png32位中的alpha透明通道的效果. 图像是由rgb三个通道以及在每个像素上定义的颜色组成的.但是在他们之上还有第四个通道,alpha通道,通过亮度定义每个像素上的透明度.白色意味着不透明,黑色意味着透明,介于黑白之间的灰色表示半透明.你可以看到下面的图片 给一个html元素使用css遮罩,就会这样处理.不用给图片应用一个alpha通道,只需要给一个图片

CSS遮罩效果和毛玻璃效果

前面的话 本文将详细介绍CSS遮罩效果和毛玻璃效果 遮罩效果 普通遮罩 一般地,处理全屏遮罩的方法是使用额外标签 <style>.overlay{ position:fixed; top: 0;right: 0;left: 0;bottom: 0; background:rgba(0,0,0,0.8); } .lightbox{ position:absolute; top: 0;right: 0;left: 0;bottom: 0; margin:auto; z-index:1; width

DIV CSS遮罩层

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DIV CSS遮罩层</title&

CSS3转换 | css遮罩

<!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>CSS3转换 | css遮罩</title> <script>   function showDiv(){    document.getElementById('bg').sty

css遮罩层

父元素:position:fixed; 让子元素居中对齐:position:absolute;top:0;bottom:0;left:0;right:0;margin:auto; <style> .loading{width:100%;height:100%;position:fixed;top:0;left:0;z-index:100;background:#fff;} .loading .pic {width:50px;height:50px;background:url(images/l

CSS遮罩层,全兼容

<script type="text/javascript"> $(function(){ $('#divLocker').css({ "position": "absolute", "margin-left": 0, "margin-top": 0, "background": "rgba(0, 0, 0, 0.8)", "height&quo

div+css 遮罩层

CSS样式部分: ---------------------------------- <style type="text/css">#loading-mask{        position:absolute;        left:0;        top:0;        width:100%;        height:100%;        z-index:20000;        background-color:gray;    }    #lo

JS+CSS简单实现DIV遮罩层显示隐藏【转藏】

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>DIV CSS遮罩层</title

JS与CSS实现遮罩层及弹出层效果

其实就是事先在网页里加入两个div框,控制显隐实现的功能. 以下为实现代码(非本人原创,网上找的,我对CSS不感冒): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xht