【代码】js/css/html - 漂亮的随机色背景渐变效果

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style> * { padding: 0; margin: 0; transition: inherit; } body { width: 100vw; height: 100vh; font-size: 3em; padding: 30px; transition: 2s; display: flex; justify-content: center; align-items: center; background: #34495e; color: #34495e; } span { font: bold; } </style>
</head>

<body>
  <h1>lawsssscat.com</h1>
  <span>hd</span>
</body>
<script> function Color(elem) { this.elem = elem this.colors = ['#f1c40f', '#2ecc71', '#e74c3c', '#9b59b6']; this.run = function (target = 'background') { setInterval(() => { let i = Math.floor(Math.random() * this.colors.length) this.elem.style[target] = this.colors[i]; }, 1000) } } new Color(document.body).run(); let h1 = new Color(document.querySelector('h1')) h1.run(); h1.run('color') </script>

</html>
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-23 18:30
美团优选内容调整,屁股都没离开座椅呢,多多买菜来挖了
熬夜脱发码农:哈,拼多多真挖人是吧
投递美团等公司10个岗位 >
点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务