前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HTML+css+js代码春节灯笼

HTML+css+js代码春节灯笼

作者头像
佛系豪豪吖
发布2023-02-23 16:56:05
1.1K0
发布2023-02-23 16:56:05
举报
文章被收录于专栏:智慧分享屋智慧分享屋
元旦了,给自己的网站也装饰个灯笼吧~

创建一个css文件和js文件,把代码粘贴进去,index.html引入css和js,就可以实现啦,快来试试吧!

1.编写CSS代码部分

代码语言:javascript
复制
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.lantern-box {
    position: fixed;
    pointer-events: none;
}
.lantern-light {
    position: relative;
    width: 120px;
    height: 90px;
    background-color: #d8000f;
    margin: 50px;
    border-radius: 50%;
    box-shadow: -5px 5px 50px 4px #fa6c00;
    animation: swing 3s infinite ease-in-out;
}
.lantern-light::before,.lantern-light::after {
    content:"";
    position: absolute;
    border:1px solid #dc8f03;
    width: 60px;
    height: 12px;
    background: linear-gradient(to right,#dc8f03,#ffa500,#dc8f03,#ffa500,#dc8f03);
    margin-left: 20px;
    left: 10px;
}
.lantern-light::before{
    top: -7px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}
.lantern-light::after {
    bottom: -7px;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
}
.lantern-line {
    width: 2px;
    height: 50px;
    background-color: #dc8f03;
    position: absolute;
    top: -50px;
    left: 60px;
}
.lantern-circle,.lantern-rect {
    height: 90px;
    border-radius: 50%;
    border: 2px solid #dc8f03;
    background-color: rgba(216,0,15,.1);
}
.lantern-circle {
    width: 100px;
    margin:12px 8px 8px 10px;
}
.lantern-rect {
    margin: -2px 8px 8px 26px;
    width: 45px;
}
.lantern-text {
    font:bold 2rem / 85px 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
    text-align: center;
    color:#dc8f03;
}
.lantern-tassel-top {
    width: 5px;
    height: 20px;
    background-color: #ffa500;
    border-radius: 0 0 5px 5px;
    position: relative;
    margin:-5px 0 0 59px;
    animation: swing 3s infinite ease-in-out;
}
.lantern-tassel-middle,.lantern-tassel-bottom {
    position: absolute;
    width: 10px;
    left: -2px;
}
.lantern-tassel-middle{
    border-radius: 50%;
    top: 14px;
    height: 10px;
    background-color: #dc8f03;
    z-index: 2;
}
.lantern-tassel-bottom  {
    background-color: #ffa500;
    border-bottom-left-radius: 5px;
    height: 35px;
    top: 18px;
    z-index: 1;
}
@keyframes swing {
    0% {
        transform: rotate(-10deg);
    }
    50% {
        transform: rotate(10deg);
    }
    100% {
        transform: rotate(-10deg);
    }
}
.container .lantern-box:first-child{
    left: 10px;
    top: -30px;
}
.container .lantern-box:nth-child(2) {
    left: 160px;
    top: -25px;
}
.container .lantern-box:nth-child(3) {
    right: 160px;
    top: -28px;
}
.container .lantern-box:last-child {
    right: 10px;
    top: -26px;
}

2.编写JavaScript代码部分

代码语言:javascript
复制
const fonts = ['新', '年', '快', '乐'];
const createLayOut = (value) => `
        <div class="lantern-box">
            <div class="lantern-light">
                <div class="lantern-line"></div>
                <div class="lantern-circle">
                    <div class="lantern-rect">
                        <div class="lantern-text">${value}</div>
                    </div>
                </div>
                <div class="lantern-tassel-top">
                    <div class="lantern-tassel-middle"></div>
                    <div class="lantern-tassel-bottom"></div>
                </div>
            </div>
        </div>
    `;
let containerHTML = '';
fonts.forEach(item => containerHTML += createLayOut(item));
document.querySelector('.container').innerHTML = containerHTML;

3.编写index.html代码部分

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新年快乐</title>

<link rel="stylesheet" href="http://rj3b.ylxhgbhsh.cn/css/index.css">

</head>
<body>

<div class="container"></div>

<script src="http://rj3b.ylxhgbhsh.cn/js/index.js"></script>

</body>
</html>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-01-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 元旦了,给自己的网站也装饰个灯笼吧~
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档