// 封装代码
function meihua() { ?>
(function ($) {
$.fn.snow = function () {
const opts = {
min: 10, //雪花的最小尺寸
max: 15, //最大尺寸
f: 500, //出现的频率,值越小雪花越多
color: "#267aba", //雪花的颜色
time: 20 //0为不限制时间,单位为秒
}
, $s_w = $('').css({
position: 'fixed',
top: 0,
zIndex: 3000,
height: '100vh',
width: '100vw',
userSelect: 'none',
pointerEvents: 'none',
color: opts.color
})
, $s = $('').css({ 'position': 'absolute', 'top': '-50px' }).html('❤️')
, h = $(window).height()
, w = $(window).width();
$s_w.appendTo('body');
const interval = setInterval(function () {
const s_l = Math.max(Math.random() * w - 50, 0)
, o = 0.5 + Math.random()
, s = opts.min + Math.random() * opts.max
, e_l = Math.min(s_l + Math.random() * 200, w - 25)
, d = h * 10 + Math.random() * 5000;
$s.clone().appendTo($s_w).css({
top: 0,
left: s_l,
opacity: o,
fontSize: s,
}).animate({
top: h,
left: e_l,
opacity: 0.2
}, d, 'linear', function () {
$(this).remove()
});
}, opts.f);
if(opts.time) {
setTimeout(function() { clearInterval(interval);} ,opts.time * 1000);
}
};
})(jQuery);
$(function () {
$.fn.snow();
});