看到保罗的博客上有一篇介绍让文字抖动的文章,心想可能以后会用的到,便再此做个记录。
以下是示例代码
<style>
/*文字摇摆*/
@keyframes shake-it{
0%{
text-shadow: 0 0 rgba(0, 255, 255, .5), 0 0 rgba(255, 0, 0, .5);
}
25%{
text-shadow: -2px 0 rgba(0, 255, 255, .5), 2px 0 rgba(255, 0, 0, .5);
}
50%{
text-shadow: -5px 0 rgba(0, 255, 255, .5), 3px 0 rgba(255, 0, 0, .5);
}
100%{
text-shadow: 3px 0 rgba(0, 255, 255, .5), 5px 0 rgba(255, 0, 0, .5);
}
}
</style>
<button id=aaa>请点我吧!</button>
<script>
function paul_shake(action, selector) {
var status = false;
action.addEventListener("click", function () {
if(status === true){
status = false;
selector.style = "";
}
else{
status = true;
selector.style = "animation: shake-it .5s reverse infinite cubic-bezier(0.68, -0.55, 0.27, 1.55)";
}
})
}
paul_shake(aaa, document.body);
</script>
抖动的文字
第二种方法。
样式css
.douyin{
animation: uk-text-shadow-glitch .65s cubic-bezier(1,-2.91,0,3.79) 0s infinite normal both running;
}
@keyframes uk-text-shadow-glitch {
0% {
text-shadow: none
}
25% {
text-shadow: -2px -2px 0 #ff0048,2px 2px 0 #3234ff
}
50% {
text-shadow: 2px -2px 0 #ff0048,-2px 2px 0 #3234ff
}
75% {
text-shadow: -2px 2px 0 #ff0048,2px -2px 0 #3234ff
}
100% {
text-shadow: 2px 2px 0 #ff0048,-2px -2px 0 #3234ff
}
}
@keyframes uk-flicker {
0% {
opacity: 0
}
10% {
opacity: .6;
transform: scale(.8)
}
20% {
opacity: 0
}
40% {
opacity: 1
}
50% {
opacity: .2;
transform: scale(1.1)
}
100% {
opacity: 1;
transform: scale(1)
}
}
cubic-bezier(1,-2.91,0,3.79)
是贝赛尔曲线,数值越大,抖的越厉害。
调用,加上类名就可以了。
抖动的文字
<p class="douyin">抖动的文字</p>