jquery插件實現(xiàn)代碼雨特效
更新時間:2021年04月23日 17:10:33 作者:阿飛超努力
這篇文章主要為大家詳細介紹了jquery插件實現(xiàn)代碼雨特效,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了jquery插件實現(xiàn)代碼雨特效的具體代碼,供大家參考,具體內(nèi)容如下
代碼雨特效
提供大概思路,雖然和目標的效果不一樣,但是很容易舉一反三改出對應效果的
效果如下
代碼部分
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>做個代碼雨</title> <script src="js/jquery-3.4.1.min.js"></script> <style> *{ margin: 0px; padding: 0px; user-select:none; } #div{ position: fixed; top: 0px; bottom: 0px; left: 0px; right: 0px; background-color: black; z-index: 1; } .item{ font-size: 12px; position: absolute; top: 0px; bottom: 0px; color: #2ecc71; -webkit-writing-mode:vertical-lr; /* animation: down 0.9s linear; */ } /* 繪制動畫幀 */ @keyframes down{ from{} to{ opacity: 0; top: 100%; } } </style> </head> <body> <div id="div"> </div> </body> </html> <script> var count = 15//每次產(chǎn)生多少條 var time = 200//刷新間隔 var num = 15//每條至多產(chǎn)生多少個字符 var span = 1000//每條數(shù)據(jù)動畫效果持續(xù)時間 var tdown = 900//每條動畫最多持續(xù)多久 $(document).ready(function(){ setInterval(function(){ for(var i = 0;i<count;i++){ var str = getchar(num)//隨機產(chǎn)生亂碼 drawitem(str)//隨機產(chǎn)生dom,然后給動畫效果 } },time) }) function drawitem(str){ var op = parseFloat((Math.random()*1).toFixed(2));//初始透明度 var top = Math.floor(Math.random()*100)//初始高度 var left = Math.floor(Math.random()*100)//初始左距 var $item = $("<div class='item'>"+str+"</div>"); $item.appendTo($("#div")); var tspan = parseFloat(Math.floor(Math.random()*tdown)/1000) tspan=tspan<=0.5?0.5:tspan $item.css({ 'top':top+'%', 'left':left+'%', 'opacity':op, 'animation':'down '+tspan+'s linear' }) setTimeout(function(){ $item.remove(); },span) } function getchar(num){//隨機產(chǎn)生一堆字符 num=num==undefined?1:Math.floor(Math.random()*num); var str = ""; for(var i = 0;i<num;i++){ var n = Math.floor(Math.random()*256) n =String.fromCharCode(n); str+=n; } return str; } </script>
思路解釋
代碼里面有注釋
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
jQuery EasyUI ProgressBar進度條組件
這篇文章主要為大家詳細介紹了jQuery EasyUI ProgressBar進度條組件的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02jQuery Validation Engine驗證控件調用外部函數(shù)驗證的方法
這篇文章主要介紹了jQuery Validation Engine驗證控件調用外部函數(shù)驗證的方法,需要的的朋友參考下吧2017-01-01jQuery實現(xiàn)固定在網(wǎng)頁頂部的菜單效果代碼
這篇文章主要介紹了jQuery實現(xiàn)固定在網(wǎng)頁頂部的菜單效果,通過jquery頁面scroll事件及邊距計算實現(xiàn)網(wǎng)頁的菜單固定效果,非常簡單實用,需要的朋友可以參考下2015-09-09