图片抠图片 mask-img 属性(透视抠图),含代码 - 案例篇
主要代码提示(css属性):
mask-image:
mask-mode:
mask-repeat:
mask-position:
mask-clip:
mask-origin:
mask-size:
mask-type:
mask-composite:
上述属性,注意兼容性写法。
案例 · html代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Swiper demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<!-- Link Swiper's CSS -->
<link rel="stylesheet" href="statics/plugin/hz_plugin/swiper/swiper.min.css">
<!-- Demo styles -->
<style>
html, body {
position: relative;
height: 100%;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color:#000;
margin: 0;
padding: 0;
}
.swiper-container {
width: 100%;
height: 100%;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
/*列表区域*/
.dhwrap{}
.dhbox{
width: 215px;
height: 215px;
margin: 0 auto;
background: none;
text-align: center;
}
.filterimg {
width: 215px;
height: 215px;
margin: 0 auto;
overflow: hidden;
color: #fff;
-webkit-mask-image: url(statics/images/hz_images/doctors/filter.png);
-webkit-mask-size: 215px 215px;
}
/*悬浮演示*/
.dhbox:hover{background: url(statics/images/hz_images/doctors/filter-on.png) no-repeat center center;background-size: 100% 100%;}
</style>
</head>
<body>
<!-- Swiper -->
<div class="swiper-container swiper-doctor">
<div class="swiper-wrapper">
<div class="swiper-slide sw-doctor">
<a href="">
<div class="dhwrap">
<div class="dhbox">
<div class="filterimg" style="background: url(statics/images/hz_images/doctors/default-mm.png) no-repeat center center;"></div>
</div>
</div>
</a>
</div>
<div class="swiper-slide">
<a href="">
<div class="dhwrap">
<div class="dhbox">
<div class="filterimg" style="background: url(statics/images/hz_images/doctors/default-mm.png) no-repeat center center;"></div>
</div>
</div>
</a>
</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination"></div>
<!-- Add Arrows -->
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
</div>
<!-- Swiper JS -->
<script src="statics/plugin/hz_plugin/swiper/swiper.min.js"></script>
<!-- Initialize Swiper -->
<script>
var swiper = new Swiper('.swiper-doctor', {
slidesPerView: 4,
spaceBetween: 30,
loop: true,
grabCursor: true,
autoplay: {
delay: 2500,
disableOnInteraction: false,
},
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
}
});
</script>
</body>
</html>
效果 · 截图示下:
附件:
- 资源下载地址
注意事项:
mask-img
可以设置抠图的尺寸(mask-size
),就像background-size一样。
-webkit-mask-image: url(statics/images/hz_images/doctors/filter.png); -webkit-mask-size: 215px 215px;
- 注意案例的代码演示。
- 参考文章
- 点击查看 jb51.net
以上就是关于“ 图片抠图片 mask-img 属性(透视抠图),含代码 - 案例篇 ” 的全部内容。