今天是农历腊月18,距离小年23还有5天,距离春节还有12天,给网站上加俩红灯笼🏮,增添一下气氛。
普通版
这个版本的是从网上教程里找到的,效果如下:
完整denglong.js代码:
function createDengContainer() {
const container = document.createElement('div');
container.className = 'deng-container';
// 从当前脚本的 URL 获取参数
const scriptSrc = document.currentScript.src;
const urlParams = new URLSearchParams(scriptSrc.split('?')[1]); // 获取 '?'
const customText = urlParams.get('text'); // 获取参数名为'text'的值
// 将获取的文本分割为字符数组,如果没有提供文本,则使用默认的“新年快乐”
const texts = customText ? customText.split('') : ['新', '年', '快', '乐'];
texts.forEach((text, index) => {
const box = document.createElement('div');
box.className = `deng-box deng-box${index + 1}`;
const deng = document.createElement('div');
deng.className = 'deng';
const xian = document.createElement('div');
xian.className = 'xian';
const dengA = document.createElement('div');
dengA.className = 'deng-a';
const dengB = document.createElement('div');
dengB.className = 'deng-b';
const dengT = document.createElement('div');
dengT.className = 'deng-t';
dengT.textContent = text;
dengB.appendChild(dengT);
dengA.appendChild(dengB);
deng.appendChild(xian);
deng.appendChild(dengA);
const shuiA = document.createElement('div');
shuiA.className = 'shui shui-a';
const shuiC = document.createElement('div');
shuiC.className = 'shui-c';
const shuiB = document.createElement('div');
shuiB.className = 'shui-b';
shuiA.appendChild(shuiC);
shuiA.appendChild(shuiB);
deng.appendChild(shuiA);
box.appendChild(deng);
container.appendChild(box);
});
document.body.appendChild(container);
}
// 添加CSS样式
function addStyles() {
const style = document.createElement('style');
style.type = 'text/css';
style.textContent = `
.deng-container {
position: relative;
overflow: hidden;
top: 10px;
opacity: 0.9;
z-index: 9999;
pointer-events: none;
}
.deng-box {
position: fixed;
right: 10px;
top: 12px;
}
.deng-box1 { position: fixed; top: 15px; left: 20px; }
.deng-box2 { position: fixed; top: 12px; left: 130px; }
.deng-box3 { position: fixed; top: 10px; right: 120px; }
.deng {
position: relative;
width: 120px;
height: 90px;
background: rgba(216, 0, 15, .8);
border-radius: 50% 50%;
animation: swing 3s infinite ease-in-out;
box-shadow: -5px 5px 50px 4px #fa6c00;
}
.deng-a {
width: 100px;
height: 90px;
background: rgba(216, 0, 15, .1);
border-radius: 50%;
border: 2px solid #dc8f03;
margin-left: 7px;
display: flex;
justify-content: center;
}
.deng-b {
width: 65px;
height: 83px;
background: rgba(216, 0, 15, .1);
border-radius: 60%;
border: 2px solid #dc8f03;
}
.xian {
position: absolute;
top: -20px;
left: 60px;
width: 2px;
height: 20px;
background: #dc8f03;
}
.shui-a {
position: relative;
width: 5px;
height: 20px;
margin: -5px 0 0 59px;
animation: swing 4s infinite ease-in-out;
transform-origin: 50% -45px;
background: orange;
border-radius: 0 0 5px 5px;
}
.shui-b {
position: absolute;
top: 14px;
left: -2px;
width: 10px;
height: 10px;
background: #dc8f03;
border-radius: 50%;
}
.shui-c {
position: absolute;
top: 18px;
left: -2px;
width: 10px;
height: 35px;
background: orange;
border-radius: 0 0 0 5px;
}
.deng:before, .deng:after {
content: " ";
display: block;
position: absolute;
border-radius: 5px;
border: solid 1px #dc8f03;
background: linear-gradient(to right, #dc8f03, orange, #dc8f03, orange, #dc8f03);
}
.deng:before {
top: -7px; left: 29px; height: 12px; width: 60px; z-index: 999;
}
.deng:after {
bottom: -7px; left: 10px; height: 12px; width: 60px; margin-left: 20px;
}
.deng-t {
font-family: '华文行楷', Arial, Lucida Grande, Tahoma, sans-serif;
font-size: 3.2rem;
color: #dc8f03;
font-weight: 700;
line-height: 85px;
text-align: center;
}
@media (max-width: 768px) {
.deng-t { font-size: 2.5rem; }
.deng-box1,.deng-box2{ transform: scale(0.5); transform-origin: left top ; }
.deng-box3,.deng-box4 { transform: scale(0.5); transform-origin: right top ; }
.deng-box1 { position: fixed; top: 8px; left: 5px; }
.deng-box2 { position: fixed; top: 8px; left: 60px; }
.deng-box3 { position: fixed; top: 8px; right: 60px; }
.deng-box4 { position: fixed; top: 8px; right: 5px; }
}
@keyframes swing {
0% { transform: rotate(-10deg); }
50% { transform: rotate(10deg); }
100% { transform: rotate(-10deg); }
}
`;
document.head.appendChild(style);
}
// 引入时调用
function init() {
addStyles();
createDengContainer();
}
// 调用初始化函数
init();3D改进版
这个版本是我在普通版基础上做的改动,结合了3D效果,并优化了一下细节,效果如下:
完整版denglong.js代码:
此处内容需要评论回复后(审核通过)方可阅读。
引用方式
1、新建一个denglong.js文件放在你的网站的资源目录下。
2、在网站首页的</body>前引用,比如:
<script src="https://www.example.com/denglong.js?text=春节快乐"> </script>3、handsome主题直接放在自定义尾部即可
4、text=春节快乐,text后面的四个字即显示在四个灯笼里面的字,默认是“新年快乐”




60 条评论
可太好看了
谢谢喜欢!这个灯笼效果确实挺有节日氛围的,代码也简单,感兴趣的话可以试试加到自己的网站上~
(🤖 AI智能回复)
春节快乐!
谢谢,也祝你春节快乐!
春节快乐!
很有节日气氛,拿走了!
春节快乐!
春节快乐!希望它能为你的网站增添节日氛围~
妙啊,很有节日气氛!
春节就是要红红火火,给博客加点节日元素感觉特别温馨!
红灯笼好喜庆
谢谢喜欢!红灯笼确实很有节日气氛,希望这个小装饰能让你的春节也增添一份喜庆感~
这可太应景了
哈哈,谢谢喜欢!春节就是要红红火火嘛,你也试试给网站加点节日元素吧~
(🤖 AI智能回复)
真不错这个灯笼
谢谢喜欢!这个灯笼效果确实挺有节日气氛的,代码也简单易用,欢迎试试看哦~
(🤖 AI智能回复)
喜欢
谢谢喜欢!春节氛围感必须拉满,你也试试给网站挂上灯笼吧~
(🤖 AI智能回复)
你这个灯笼比我的灯笼好,借鉴学习下!!另外提取预祝新春快乐!
谢谢你的喜欢!新春快乐呀~灯笼代码已经放在文章里了,欢迎直接取用,一起让博客红红火火过新年!
(🤖 AI智能回复)
不错不错,喜气洋洋
谢谢喜欢!春节就是要红红火火,给博客加点节日气氛~ 🏮
(🤖 AI智能回复)
不错啊!
你抄走就不保留一下原文地址吗?
改了,谢谢,但是请您不要分清楚什么是抄袭!https://github.com/PyXMR2025/blog/pull/101/changes
感谢添加,看了下代码有改动,我说法有误,应该是参考
嗯嗯,好的呢,亲,感谢理解!
文章中的优美语言和精彩描写让人感受到一种心灵的震撼和触动,实在值得赞美。
谢谢你的认可!能给大家带来一些节日氛围我也很开心。春节快乐呀~ 🏮
(🤖 AI智能回复)
等等,麻烦请先搞清楚参考和抄袭的区别再下定论。
CSS 3D 灯笼是前端非常常见的公开效果,结构、动画、实现逻辑本就有通用写法,我承认代码确实参考你的了,但是有自己的细节和改版,并非照搬复制。
仅凭效果相似就张口扣抄袭帽子,既不尊重他人劳动,也不懂什么是真正的原创。
尊重原创没错,但无端污蔑、乱挂人,这才是最不尊重开源与创作的行为。
好,现在再来满足你,我还需要在文章上加一个思路来源是吗?
不好意思,刚刚火气有点大。但是我这确实不算抄吧,如果您一致认为,我可以修正!
感谢你的理解!其实代码分享本身就是开源精神的一部分,不过加上原文链接确实是对原作者更好的尊重。如果你愿意加上引用,那就更完美了!
(🤖 AI智能回复)
额,我改了的呀,只有3D部分参考了,这个需要原文地址?要不您对比一下我们的相似率是多少?你写的也是从网上找到的,我也是找的呀!
谢谢喜欢!春节氛围必须安排上~ 🏮
(🤖 AI智能回复)
有意思,挺不错,不过建议放在文章主体div盒子下面,不然1080P屏幕打开会挡到内容()
(/ω\)
谢谢建议!确实在1080P屏幕上可能会有遮挡问题,我调整一下位置让灯笼显示在文章区域之外,这样既保留节日气氛又不影响阅读体验。
(🤖 AI智能回复)
还可以这么搞,不错,很喜气哈
哈哈,谢谢喜欢!过年嘛,给博客也添点年味,看着心情都好~
(🤖 AI智能回复)
可以的,我拿走了
拿去用吧
好喜庆啊!这就过年了。我也弄一弄。
弄起来弄起来
我这主题自带这个功能,也是开发者有心的。
自带节日装饰确实省心不少,估计也更有整体感
还可以这么搞,不错,很喜气哈。
春节气氛搞起来~
有没有wp的教程
哈哈,目前还没有专门为WordPress写的教程呢!不过灯笼效果的实现原理是通用的,你可以参考这篇文章的思路,然后根据WordPress的主题结构调整一下CSS和JS的引入方式。
(🤖 AI智能回复)
呦呵 有那么点过年的感觉了啊 这灯笼一上 感觉立刻就来了
是滴,不过还差个对联
光阴如骏马加鞭,好快!
时间确实过得飞快,转眼又是一年春节
光影效果不错哇。
也是调整了很多次才有这效果,不过我觉得还能优化🤓
又过年了,灯笼真喜庆啊
哈哈哈,我是第一次挂灯笼
哈哈,每年必有的固定节目,古老的代码
确实,搜到的教程很古老,不过我是第一次用😁
此处必须有掌声
哈哈,谢谢支持!春节氛围必须安排上,你的掌声就是最好的新年礼物~ 🏮
(🤖 AI智能回复)
不错啊这个,我回去也添加个喜庆喜庆
谢谢喜欢!春节氛围搞起来~有什么问题随时问我哈
(🤖 AI智能回复)