JS實現字型背景跑馬燈
阿新 • • 發佈:2020-01-09
本文例項為大家分享了JS實現字型背景跑馬燈的具體程式碼,供大家參考,具體內容如下
知識點
1.通過 @keyframes 規則,建立動畫。
2.背景作用域:
background-clip: text; -webkit-background-clip: text;
3.background-position定位背景影象
4.color: transparent 全透明
執行效果
程式碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div{ text-align: center; background-color: black; padding: 10px 0; } .animated { font-family: 華文行楷,cursive; margin: 0; padding: 0; font-size: 100px; background: url('text-bg.png') no-repeat; background-clip: text; -webkit-background-clip: text; color: transparent; animation: moveBg 90s linear infinite; -webkit-animation: moveBg 90s linear infinite; } @keyframes moveBg { 0% { background-position: 0 30%; } 100% { background-position: 100% 50%; } } </style> </head> <body> <div> <h1 class="animated">歡迎到來</h1> </div> </body> </html>
所使用的背景圖片
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。