JavaScript Html實(shí)現(xiàn)移動(dòng)端紅包雨功能頁(yè)面
本文實(shí)例為大家分享了Html實(shí)現(xiàn)移動(dòng)端紅包雨功能頁(yè)面的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)效果如下:
具體代碼如下
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='http://www.aoyou183.cn/bcjs/css/demo.css' > <link rel='stylesheet' href='http://www.aoyou183.cn/bcjs/css/index.css' ></head><body> <!-- 紅包 --> <ul class='redPaper'> <!-- <li> <a href='http://www.aoyou183.cn/bcjs/14232.html#' rel='external nofollow' ><img src='http://www.aoyou183.cn/bcjs/images/hb_1.png' alt=''></a> </li> --> </ul> <div class='backward'> <span></span> </div> <script src='http://www.aoyou183.cn/bcjs/js/jquery.min.js'></script> <script src='http://www.aoyou183.cn/bcjs/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();})
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)2. 將properties文件的配置設(shè)置為整個(gè)Web應(yīng)用的全局變量實(shí)現(xiàn)方法3. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法4. 得到XML文檔大小的方法5. ASP.NET Core實(shí)現(xiàn)中間件的幾種方式6. 如何在jsp界面中插入圖片7. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫(kù)的方法8. 利用CSS3新特性創(chuàng)建透明邊框三角9. XML入門的常見(jiàn)問(wèn)題(二)10. ASP常用日期格式化函數(shù) FormatDate()
