本文最后更新于2022年7月10日,已超过 1 年没有更新,如果文章内容失效,请 反馈 给我们,谢谢!
有两种方法随便选一种即可。
网站下雪代码一:
<span class="tag"><script</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"text/javascript"</span><span class="tag">></span> <span class="pun">(</span><span class="kwd">function</span><span class="pun">(</span><span class="pln">$</span><span class="pun">){</span><span class="pln"> $</span><span class="pun">.</span><span class="pln">fn</span><span class="pun">.</span><span class="pln">snow </span><span class="pun">=</span> <span class="kwd">function</span><span class="pun">(</span><span class="pln">options</span><span class="pun">){</span> <span class="kwd">var</span><span class="pln"> $flake </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'<div id="snowbox" />'</span><span class="pun">).</span><span class="pln">css</span><span class="pun">({</span><span class="str">'position'</span><span class="pun">:</span> <span class="str">'absolute'</span><span class="pun">,</span><span class="str">'z-index'</span><span class="pun">:</span><span class="str">'9999'</span><span class="pun">,</span> <span class="str">'top'</span><span class="pun">:</span> <span class="str">'-50px'</span><span class="pun">}).</span><span class="pln">html</span><span class="pun">(</span><span class="str">'❄'</span><span class="pun">),</span><span class="pln"> documentHeight </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="pln">document</span><span class="pun">).</span><span class="pln">height</span><span class="pun">(),</span><span class="pln"> documentWidth </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="pln">document</span><span class="pun">).</span><span class="pln">width</span><span class="pun">(),</span><span class="pln"> defaults </span><span class="pun">=</span> <span class="pun">{</span><span class="pln"> minSize </span><span class="pun">:</span> <span class="lit">10</span><span class="pun">,</span><span class="pln"> maxSize </span><span class="pun">:</span> <span class="lit">20</span><span class="pun">,</span><span class="pln"> newOn </span><span class="pun">:</span> <span class="lit">1000</span><span class="pun">,</span><span class="pln"> flakeColor </span><span class="pun">:</span> <span class="str">"#AFDAEF"</span> <span class="com">/* 此处可以定义雪花颜色,若要白色可以改为#FFFFFF */</span> <span class="pun">},</span><span class="pln"> options </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">.</span><span class="pln">extend</span><span class="pun">({},</span><span class="pln"> defaults</span><span class="pun">,</span><span class="pln"> options</span><span class="pun">);</span> <span class="kwd">var</span><span class="pln"> interval</span><span class="pun">=</span><span class="pln"> setInterval</span><span class="pun">(</span> <span class="kwd">function</span><span class="pun">(){</span> <span class="kwd">var</span><span class="pln"> startPositionLeft </span><span class="pun">=</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span><span class="pln"> documentWidth </span><span class="pun">-</span> <span class="lit">100</span><span class="pun">,</span><span class="pln"> startOpacity </span><span class="pun">=</span> <span class="lit">0.5</span> <span class="pun">+</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">(),</span><span class="pln"> sizeFlake </span><span class="pun">=</span><span class="pln"> options</span><span class="pun">.</span><span class="pln">minSize </span><span class="pun">+</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span><span class="pln"> options</span><span class="pun">.</span><span class="pln">maxSize</span><span class="pun">,</span><span class="pln"> endPositionTop </span><span class="pun">=</span><span class="pln"> documentHeight </span><span class="pun">-</span> <span class="lit">200</span><span class="pun">,</span><span class="pln"> endPositionLeft </span><span class="pun">=</span><span class="pln"> startPositionLeft </span><span class="pun">-</span> <span class="lit">500</span> <span class="pun">+</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span> <span class="lit">500</span><span class="pun">,</span><span class="pln"> durationFall </span><span class="pun">=</span><span class="pln"> documentHeight </span><span class="pun">*</span> <span class="lit">10</span> <span class="pun">+</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span> <span class="lit">5000</span><span class="pun">;</span><span class="pln"> $flake</span><span class="pun">.</span><span class="pln">clone</span><span class="pun">().</span><span class="pln">appendTo</span><span class="pun">(</span><span class="str">'body'</span><span class="pun">).</span><span class="pln">css</span><span class="pun">({</span><span class="pln"> left</span><span class="pun">:</span><span class="pln"> startPositionLeft</span><span class="pun">,</span><span class="pln"> opacity</span><span class="pun">:</span><span class="pln"> startOpacity</span><span class="pun">,</span> <span class="str">'font-size'</span><span class="pun">:</span><span class="pln"> sizeFlake</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">:</span><span class="pln"> options</span><span class="pun">.</span><span class="pln">flakeColor </span><span class="pun">}).</span><span class="pln">animate</span><span class="pun">({</span><span class="pln"> top</span><span class="pun">:</span><span class="pln"> endPositionTop</span><span class="pun">,</span><span class="pln"> left</span><span class="pun">:</span><span class="pln"> endPositionLeft</span><span class="pun">,</span><span class="pln"> opacity</span><span class="pun">:</span> <span class="lit">0.2</span> <span class="pun">},</span><span class="pln">durationFall</span><span class="pun">,</span><span class="str">'linear'</span><span class="pun">,</span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"> $</span><span class="pun">(</span><span class="kwd">this</span><span class="pun">).</span><span class="pln">remove</span><span class="pun">()</span> <span class="pun">});</span> <span class="pun">},</span><span class="pln"> options</span><span class="pun">.</span><span class="pln">newOn</span><span class="pun">);</span> <span class="pun">};</span> <span class="pun">})(</span><span class="pln">jQuery</span><span class="pun">);</span><span class="pln"> $</span><span class="pun">(</span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"> $</span><span class="pun">.</span><span class="pln">fn</span><span class="pun">.</span><span class="pln">snow</span><span class="pun">({</span><span class="pln"> minSize</span><span class="pun">:</span> <span class="lit">5</span><span class="pun">,</span> <span class="com">/* 定义雪花最小尺寸 */</span><span class="pln"> maxSize</span><span class="pun">:</span> <span class="lit">50</span><span class="pun">,</span><span class="com">/* 定义雪花最大尺寸 */</span><span class="pln"> newOn</span><span class="pun">:</span> <span class="lit">300</span> <span class="com">/* 定义密集程度,数字越小越密集 */</span> <span class="pun">});</span> <span class="pun">});</span> <span class="tag"></script></span>
网站下雪代码二:
<span class="tag"><script</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"text/javascript"</span><span class="tag">></span> <span class="pun">(</span><span class="kwd">function</span><span class="pun">(</span><span class="pln">$</span><span class="pun">){</span><span class="pln"> $</span><span class="pun">.</span><span class="pln">fn</span><span class="pun">.</span><span class="pln">snow </span><span class="pun">=</span> <span class="kwd">function</span><span class="pun">(</span><span class="pln">options</span><span class="pun">){</span> <span class="kwd">var</span><span class="pln"> $flake </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'<div id="snowbox" />'</span><span class="pun">).</span><span class="pln">css</span><span class="pun">({</span><span class="str">'position'</span><span class="pun">:</span> <span class="str">'absolute'</span><span class="pun">,</span><span class="str">'z-index'</span><span class="pun">:</span><span class="str">'9999'</span><span class="pun">,</span> <span class="str">'top'</span><span class="pun">:</span> <span class="str">'-50px'</span><span class="pun">}).</span><span class="pln">html</span><span class="pun">(</span><span class="str">'❄'</span><span class="pun">),</span><span class="pln"> documentHeight </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="pln">document</span><span class="pun">).</span><span class="pln">height</span><span class="pun">(),</span><span class="pln"> documentWidth </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="pln">document</span><span class="pun">).</span><span class="pln">width</span><span class="pun">(),</span><span class="pln"> defaults </span><span class="pun">=</span> <span class="pun">{</span><span class="pln"> minSize </span><span class="pun">:</span> <span class="lit">10</span><span class="pun">,</span><span class="pln"> maxSize </span><span class="pun">:</span> <span class="lit">20</span><span class="pun">,</span><span class="pln"> newOn </span><span class="pun">:</span> <span class="lit">1000</span><span class="pun">,</span><span class="pln"> flakeColor </span><span class="pun">:</span> <span class="str">"#AFDAEF"</span> <span class="com">/* 此处可以定义雪花颜色,若要白色可以改为#FFFFFF */</span> <span class="pun">},</span><span class="pln"> options </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">.</span><span class="pln">extend</span><span class="pun">({},</span><span class="pln"> defaults</span><span class="pun">,</span><span class="pln"> options</span><span class="pun">);</span> <span class="kwd">var</span><span class="pln"> interval</span><span class="pun">=</span><span class="pln"> setInterval</span><span class="pun">(</span> <span class="kwd">function</span><span class="pun">(){</span> <span class="kwd">var</span><span class="pln"> startPositionLeft </span><span class="pun">=</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span><span class="pln"> documentWidth </span><span class="pun">-</span> <span class="lit">100</span><span class="pun">,</span><span class="pln"> startOpacity </span><span class="pun">=</span> <span class="lit">0.5</span> <span class="pun">+</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">(),</span><span class="pln"> sizeFlake </span><span class="pun">=</span><span class="pln"> options</span><span class="pun">.</span><span class="pln">minSize </span><span class="pun">+</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span><span class="pln"> options</span><span class="pun">.</span><span class="pln">maxSize</span><span class="pun">,</span><span class="pln"> endPositionTop </span><span class="pun">=</span><span class="pln"> documentHeight </span><span class="pun">-</span> <span class="lit">200</span><span class="pun">,</span><span class="pln"> endPositionLeft </span><span class="pun">=</span><span class="pln"> startPositionLeft </span><span class="pun">-</span> <span class="lit">500</span> <span class="pun">+</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span> <span class="lit">500</span><span class="pun">,</span><span class="pln"> durationFall </span><span class="pun">=</span><span class="pln"> documentHeight </span><span class="pun">*</span> <span class="lit">10</span> <span class="pun">+</span> <span class="typ">Math</span><span class="pun">.</span><span class="pln">random</span><span class="pun">()</span> <span class="pun">*</span> <span class="lit">5000</span><span class="pun">;</span><span class="pln"> $flake</span><span class="pun">.</span><span class="pln">clone</span><span class="pun">().</span><span class="pln">appendTo</span><span class="pun">(</span><span class="str">'body'</span><span class="pun">).</span><span class="pln">css</span><span class="pun">({</span><span class="pln"> left</span><span class="pun">:</span><span class="pln"> startPositionLeft</span><span class="pun">,</span><span class="pln"> opacity</span><span class="pun">:</span><span class="pln"> startOpacity</span><span class="pun">,</span> <span class="str">'font-size'</span><span class="pun">:</span><span class="pln"> sizeFlake</span><span class="pun">,</span><span class="pln"> color</span><span class="pun">:</span><span class="pln"> options</span><span class="pun">.</span><span class="pln">flakeColor </span><span class="pun">}).</span><span class="pln">animate</span><span class="pun">({</span><span class="pln"> top</span><span class="pun">:</span><span class="pln"> endPositionTop</span><span class="pun">,</span><span class="pln"> left</span><span class="pun">:</span><span class="pln"> endPositionLeft</span><span class="pun">,</span><span class="pln"> opacity</span><span class="pun">:</span> <span class="lit">0.2</span> <span class="pun">},</span><span class="pln">durationFall</span><span class="pun">,</span><span class="str">'linear'</span><span class="pun">,</span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"> $</span><span class="pun">(</span><span class="kwd">this</span><span class="pun">).</span><span class="pln">remove</span><span class="pun">()</span> <span class="pun">});</span> <span class="pun">},</span><span class="pln"> options</span><span class="pun">.</span><span class="pln">newOn</span><span class="pun">);</span> <span class="pun">};</span> <span class="pun">})(</span><span class="pln">jQuery</span><span class="pun">);</span><span class="pln"> $</span><span class="pun">(</span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"> $</span><span class="pun">.</span><span class="pln">fn</span><span class="pun">.</span><span class="pln">snow</span><span class="pun">({</span><span class="pln"> minSize</span><span class="pun">:</span> <span class="lit">5</span><span class="pun">,</span> <span class="com">/* 定义雪花最小尺寸 */</span><span class="pln"> maxSize</span><span class="pun">:</span> <span class="lit">50</span><span class="pun">,</span><span class="com">/* 定义雪花最大尺寸 */</span><span class="pln"> newOn</span><span class="pun">:</span> <span class="lit">300</span> <span class="com">/* 定义密集程度,数字越小越密集 */</span> <span class="pun">});</span> <span class="pun">});</span> <span class="tag"></script> </span>
使用方法,下雪代码一:
复制粘贴到网站“</body>”前即可。
使用方法,下雪代码二:
复制粘贴到文本件另存为JS文件取名“snow”(名字随便取)放在网站根目录(目录随便)
复制以下代码到footer.php最后</body>之前(随便能在网站调用即可)
复制以下代码到footer.php最后</body>之前(随便能在网站调用即可)
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.3/jquery.js"></script> <script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript" src="/snow.js"></script>
注:第一段第二段是引用的百度的公共库如果网站已经引用了可以删除,最后一段才是雪花JS。
这两种网站飘雪的样式不仅适用于wordpress在所有网站都适用。