js實(shí)現(xiàn)驗(yàn)證碼干擾(靜態(tài))
本文實(shí)例為大家分享了js實(shí)現(xiàn)驗(yàn)證碼干擾的具體代碼,供大家參考,具體內(nèi)容如下
效果
代碼
<!DOCTYPE html><html> <head> <meta charset='UTF-8'> <title></title> <style> *{ padding: 0; margin: 0; } canvas{ background: #272822; } </style> </head> <body> <canvas id=’canvas’ width=’800’ height=’500’></canvas> <script> //獲得畫板 var canvas=document.getElementById(’canvas’); //獲得繪畫環(huán)境 var cv=canvas.getContext(’2d’); cv.fillStyle=’#272822’; cv.fillRect(0,0,800,500); cv.font=’80px 微軟雅黑’; cv.fillStyle=’greenyellow’; cv.fillText( Math.floor(Math.random()*10000),200,200); //獲得所有的圖像像素點(diǎn)信息 var alldata=cv.getImageData(0,0,800,500); //獲得像素點(diǎn)的個(gè)數(shù) var dian=alldata.data.length/4; for(var i=0;i<10000;i++){ //取隨機(jī)數(shù) var num=Math.floor(Math.random()*dian); //計(jì)算像素點(diǎn)對應(yīng)的四條信息從幾號開始 var start=(num-1)*4; alldata.data[start]=Math.floor(Math.random()*256); alldata.data[start+1]=Math.floor(Math.random()*256); alldata.data[start+2]=Math.floor(Math.random()*256); } //將數(shù)據(jù)寫回畫板 cv.putImageData(alldata,0,0); </script> </body></html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報(bào)錯(cuò)問題分析2. ASP中常用的22個(gè)FSO文件操作函數(shù)整理3. Vue+elementUI下拉框自定義顏色選擇器方式4. React+umi+typeScript創(chuàng)建項(xiàng)目的過程5. SharePoint Server 2019新特性介紹6. php測試程序運(yùn)行速度和頁面執(zhí)行速度的代碼7. php網(wǎng)絡(luò)安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究8. ASP的Global.asa文件技巧用法9. ASP中if語句、select 、while循環(huán)的使用方法10. html清除浮動(dòng)的6種方法示例
