CSS3发光文字字体切换特效

index.html代码

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>CSS3发光文字字体切换特效 - 站长素材</title>

<link href="https://fonts.googleapis.com/css2?family=Kirang+Haerang&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Rye&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Amatic+SC:wght@700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Lobster&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Bangers&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Fredericka+the+Great&display=swap" rel="stylesheet">

<link rel="stylesheet" href="css/style.css">

</head>
<body>

<div class="container">
  <h2 class="loki">
    <p class="letter">L</p>
    <p class="letter">O</p>
    <p class="letter">v</p>
    <p class="letter">E</p>
  </h2>
</div>

<script  src="js/script.js"></script>

</body>
</html>

css代码

html {
  font-family: 100%;
  box-sizing: border-box;
}

*, *::before, *::after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
}

body {
  height: 100vh;
  width: 100%;
  font-family: "Indie Flower", cursive;
  background-color: #121212;
  color: #ffffffda;
}

img {
  display: block;
}

.container {
  height: 100%;
  width: 100%;
  display: grid;
  place-content: center;
  background-image: url("../img/daf.png");
  background-size: cover;
}

.loki {
  font-size: 7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 30rem;
}
.loki .letter {
  text-shadow: 0 0 0.4em #ffffffda, 0 0 0.5em #ffffffda, 0 0 0.25em #ffffffda;
  mix-blend-mode: screen;
}

JavaScript 代码

const fonts = [
  'Kirang Haerang',
  'Indie Flower',
  'Rye',
   'Amatic SC',
  'Bangers',
  'Fredericka the Great'
];

const letters = document.querySelectorAll('.letter');

let count=0;

const rollIntro = () => {
  letters.forEach(letter => {
    
  let randomFontIndex = Math.floor(Math.random() * fonts.length);
    let randomFont = fonts[randomFontIndex];
  
 letter.style.fontFamily=randomFont;
});
}

let introAnimation = setInterval(function() {
  rollIntro();
  if(count>15)
    clearInterval(introAnimation);
  count++;
},350);

适用浏览器:Chrome、FireFox、360、搜狗、Opera、傲游. 不支持Windows版Safari、IE8及以下浏览器。

底图:

效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千秋TʌT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值