MediaWiki:Common.js
来自Fuckrooms Wiki
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
(function() {
// 创建样式
var style = document.createElement('style');
style.textContent = '.snowflake { position: fixed; color: #fff; z-index: 9999; user-select: none; } @keyframes fall { 0% { transform: translateY(-100vh) rotate(0deg); } 100% { transform: translateY(100vh) rotate(720deg); } }';
document.head.appendChild(style);
// 配置参数
var snowflakes = 35,
minSize = 5,
maxSize = 15,
speed = 5,
characters = ['❄', '❅', '❆'];
// 生成雪花
function createSnow() {
for(var i = 0; i < snowflakes; i++) {
var flake = document.createElement('div');
flake.className = 'snowflake';
flake.textContent = characters[Math.floor(Math.random() * characters.length)];
// 初始属性
flake.style.left = Math.random() * 100 + '%';
flake.style.fontSize = Math.random() * (maxSize - minSize) + minSize + 'px';
flake.style.animation = 'fall ' + (Math.random() * 5 + speed) + 's linear infinite';
flake.style.opacity = Math.random() * 0.5 + 0.5;
document.body.appendChild(flake);
// 随机飘动效果
setInterval(function(f) {
f.style.transform = 'translateX(' + (Math.random() * 30 - 15) + 'px)';
}, 2000, flake);
}
}
// 窗口加载后执行
window.addEventListener('load', function() {
createSnow();
window.addEventListener('resize', function() {
document.querySelectorAll('.snowflake').forEach(function(f) {
f.style.left = Math.random() * 100 + '%';
});
});
});
})();