切割的文字_codepen

本文介绍了一个使用HTML和CSS实现的骨折效果动画案例。通过精心设计的CSS伪元素和动画属性,实现了文字在输入时产生类似断裂的效果。此案例适用于前端开发者学习CSS动画技巧。

<h1 contenteditable data-heading="Fracture">Fracture</h1>
html{height: 100%;}
body{font-family: 'Roboto', sans-serif; height: 100%;}
h1{color: black; text-align: center; font-size: 10vw; font-weight: 900; text-transform: uppercase; top: 50%; left: 50%; transform: translate(-50%, -50%); position: absolute; margin: 0;}
h1:before,
h1:after{content: attr(data-heading); position: absolute; left: 0; width: 100%; text-align: center;}
h1:before{clip-path: polygon(0 0, 100% 0%, 100% 39%, 0 67%); color: white; text-shadow: 3px -2px 5px white, -3px 3px 4px white; background: white;}
h1:after{clip-path: polygon(0 0, 100% 0%, 100% 37%, 0 65%); color: black; animation: fracture 5s infinite ease;}
@keyframes fracture{0%{transform: translateX(0);} 50%{transform: translate(-20px, 2%);}}
@-webkit-keyframes fracture{0%{transform: translateX(0);} 50%{transform: translate(-20px, 2%);}}

 

window.onload=function(){
  var h1 = document.querySelector("h1");

  h1.addEventListener("input", function() {
    this.setAttribute("data-heading", this.innerText);
  });
}

 

转载于:https://www.cnblogs.com/mudeng-007/p/7737092.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值