javascript實(shí)現(xiàn)移動(dòng)端紅包雨頁面
本文實(shí)例為大家分享了js實(shí)現(xiàn)移動(dòng)端紅包雨頁面的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)習(xí)的效果如下:
具體代碼如下
html部分:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>紅包雨</title> <link rel="stylesheet" href="./css/demo.css" > <link rel="stylesheet" href="./css/index.css" > </head> <body> <!-- 紅包 --> <ul class="redPaper"> <!-- <li> <a href="#" rel="external nofollow" ><img src="./images/hb_1.png" alt=""></a> </li> --> </ul> <div class="backward"> <span></span> </div> <script src="./js/jquery.min.js"></script> <script src="./js/index.js"></script> <script> </script> </body> </html>
demo.css為初始化css,可以不加
index.css部分
body{ width: 100%; height: 100%; background-image: url(../images/bj.jpg); background-repeat: no-repeat; background-size: cover; position: relative; } .redPaper{ width: 100%; height: 100%; /* border: 1px solid black; */ overflow: hidden; } .redPaper li { position: absolute; animation: all 3s linear; top:-100px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } .redPaper li a{ display: block; } .backward{ width: 100%; background:#ccc; opacity: 0.5; position: absolute; top: 0; } .backward span{ display: inline-block; width: 100px; height: 100px; color: #000; font-weight: bold; position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: auto; text-align: center; line-height: 100px; font-size: 1000%; }
index.js部分:
$(document).ready(function () { var win = (parseInt($('.redPaper').css('width'))) - 60; console.log(win) $(".redPaper").css("height", $(document).height()); $(".backward").css("height", $(document).height()); $("li").css({}); // 點(diǎn)擊確認(rèn)的時(shí)候關(guān)閉模態(tài)層 // $(".sen a").click(function(){ // $(".mo").css("display", "none") // }); var del = function () { nums++; // console.info(nums); // console.log($(".li" + nums).css("left")); $(".li" + nums).remove(); setTimeout(del, 200) } var addRedPaper = function () { var hb = parseInt(Math.random() * (3 - 1) + 1); var randomW = parseInt(Math.random() * (70 - 30) + 20); var randomLeft = parseInt(Math.random() * win); var randomRotate = (parseInt(Math.random() * 45)) + 'deg'; // console.log(rot) num++; $(".redPaper").append("<li class='li" + num + "' ><a href='javascript:;'><img src='images/hb_" + hb + ".png' data-num ='" + num + "'></a></li>"); $(".li" + num).css({ "left": randomLeft, }); $(".li" + num + " a img").css({ "width": randomW, "transform": "rotate(" + randomRotate + ")", "-webkit-transform": "rotate(" + randomRotate + ")", "-ms-transform": "rotate(" + randomRotate + ")", /* Internet Explorer */ "-moz-transform": "rotate(" + randomRotate + ")", /* Firefox */ "-webkit-transform": "rotate(" + randomRotate + ")",/* Safari 和 Chrome */ "-o-transform": "rotate(" + randomRotate + ")" /* Opera */ }); $(".li" + num).animate({ 'top': $(window).height() + 20 }, 5000, function () { //刪掉已經(jīng)顯示的紅包 this.remove() }); //點(diǎn)擊紅包的時(shí)候彈出模態(tài)層 $(".li" + num).click(function (e) { if (e.target.tagName == 'IMG') { console.log(e.target.dataset.num) } }); setTimeout(addRedPaper, 200) } //增加紅包 var num = 0; setTimeout(addRedPaper, 3000); //倒數(shù)計(jì)時(shí) var backward = function () { numz--; if (numz > 0) { $(".backward span").html(numz); } else { $(".backward").remove(); } setTimeout(backward, 1000) } var numz = 4; backward(); })
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- JavaScript Html實(shí)現(xiàn)移動(dòng)端紅包雨功能頁面
- js+css實(shí)現(xiàn)紅包雨效果
- JavaScript+Canvas模擬實(shí)現(xiàn)支付寶畫年兔游戲
- 基于React.js實(shí)現(xiàn)兔兔牌九宮格翻牌抽獎(jiǎng)組件
- JavaScript?Canvas實(shí)現(xiàn)兼容IE的兔子發(fā)射爆破動(dòng)圖特效
- 利用JavaScript制作一個(gè)搞怪的兔子動(dòng)畫效果
- 利用JavaScript創(chuàng)建一個(gè)兔年春節(jié)倒數(shù)計(jì)時(shí)器
- 基于Three.js實(shí)現(xiàn)3D玉兔效果的示例代碼
- JS技巧動(dòng)手實(shí)現(xiàn)紅包兔子雨效果示例詳解
相關(guān)文章
利用onresize使得div可以隨著屏幕大小而自適應(yīng)的代碼
javascript 利用onresize使得div可以隨著屏幕大小而自適應(yīng)的代碼2010-01-01JavaScript 判斷一個(gè)對(duì)象{}是否為空對(duì)象的簡單方法
下面小編就為大家?guī)硪黄狫avaScript 判斷一個(gè)對(duì)象{}是否為空對(duì)象的簡單方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10innerhtml用法 innertext用法 以及innerHTML與innertext的區(qū)別
innerhtml用法 innertext用法 以及innerHTML與innertext的區(qū)別,看完這個(gè)大家以后在實(shí)際應(yīng)用中,就可以選擇合適的方法。盡可能的考慮到兼容性。2009-10-10短視頻(douyin)去水印工具的實(shí)現(xiàn)代碼
這篇文章主要介紹了市面上短視頻(douyin)"去水印"的工具原來是這樣實(shí)現(xiàn)的,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03JavaScript數(shù)組去重的3種方法和代碼實(shí)例
這篇文章主要介紹了JavaScript數(shù)組去重的3種方法和代碼實(shí)例,本文直接給出實(shí)例代碼,需要的朋友可以參考下2015-07-07javascript實(shí)現(xiàn)表單驗(yàn)證
這篇文章主要介紹了javascript實(shí)現(xiàn)表單驗(yàn)證的相關(guān)資料,以一個(gè)完整的實(shí)例對(duì)javascript實(shí)現(xiàn)表單驗(yàn)證的方法進(jìn)行分析,感興趣的小伙伴們可以參考一下2016-01-01詳解如何使用JSZip實(shí)現(xiàn)在瀏覽器中操作文件與文件夾
這篇文章主要介紹了如何使用JSZip實(shí)現(xiàn)在瀏覽器中操作文件與文件夾,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考一下2024-04-04GitHub上77.9K的Axios項(xiàng)目有哪些值得借鑒的地方詳析
提到axios,相信大家應(yīng)該都不會(huì)陌生,這篇文章主要給大家介紹了關(guān)于GitHub上77.9K的Axios項(xiàng)目有哪些值得借鑒的地方,需要的朋友可以參考下2021-06-06