css3实现渐变的iPhone滑动解锁效果

小玲

该效果的主要实现思路是给文字添加渐变的背景,然后对背景进行裁剪,按文字裁剪(目前只有webkit内核浏览器支持该属性),最后给背景添加动画,即改变背景的位置,背景动画效果如下(GIF录制时有卡顿,代码实现时不卡):

 

最终效果:

全部代码如下:

01<!DOCTYPE html>
02<html>
03<head>
04    <style>
05        p{
06            width:50%;
07            margin:0 auto;
08            line-height:50px;
09            font-size:50px;
10            text-align:center;
11             
12            -webkit-background-clip: text;    /*按文字裁剪*/       
13            -webkit-text-fill-color: transparent;    /*文字的颜色使用背景色*/   
14             
15            background-color:#19385c;    /*设置一个背景色*/       
16            background-image: -webkit-linear-gradient(-45deg, rgba(0, 0, 0, 0.6) 30%, #aff0ff 50%, rgba(0, 0, 0, 0.6) 70%);        /*设置渐变的背景,按对角线渐变*/
17             
18            background-blend-mode: hard-light;    /*设置背景为混合模式下的强光模式*/
19            background-size: 200%;
20             
21            -webkit-animation: shine 4s infinite;    /*给背景添加动画改变位置*/
22        }
23 
24        @-webkit-keyframes shine {
25          from {background-position: 100%;}
26          to {background-position: 0;}
27        }
28    </style>
29</head>
30<body><p>&gt;&nbsp;Slide To Unlock</p></body>
31</html>

需要说明的是由于按文字裁剪目前只有 webkit 内核可用,所以该效果目前不兼容其他内核浏览器。

0

登录后可发表评论,立即登录