如何使用JS实现520代码

这次给大家带来如何使用JS实现520代码,使用JS实现520代码的注意事项有哪些,下面就是实战案例,一起来看一下。

     520    html, body{padding:0px; margin:0px; background:#222; font-family: 'Karla', sans-serif; color:#FFF; height:100%; overflow:hidden;}  canvas {width:100%; height:100%;}  #text,#text_520{font-family:'楷体'; color:rgb(255,255,3); font-size:20px; position:fixed; left:10%; top:10%;}  #text_520{font-size:100px; top:50%; left:50%;}  img{position:fixed; top:0; left:0; width:100%;}  #last{font-size:12px; bottom:10px; left:50%; position:fixed;}  /*  @keyframes drop {   0% {     transform: translateY(-100px);    opacity: 0;   }   90% {    opacity: 1;    transform:translateY(10px);   }   100% {    transform:translateY(0px;)   }  }  */        

5 2 0

如何使用JS实现520代码

版权所有:李晓珂

function isIE(){ var u = navigator.userAgent; if((u.indexOf("compatible") > -1 && u.indexOf("MSIE") > -1) || (u.indexOf("Trident") > -1 && u.indexOf("rv:11.0") > -1)){ alert("该浏览器暂不支持,请更换浏览器"); window.open('','_self'); window.close(); } var audio = document.createElement("audio"); audio.setAttribute("src","./520-love.mp3"); audio.setAttribute("autoplay","autoplay"); } isIE(); var textArr = [ 'I love three things in this world,', 'the sun ,the moon and you.', 'The sun for the day,', 'the moon for the night,', 'and you forever!', '', 'If you were a teardrop,', 'in my eye,', 'for fear of losing you,', 'I would never cry.', 'And if the golden sun,', 'should cease to shine its light,', 'just one smile from you,', 'would make my whole world bright.' ]; var text_520 = document.getElementById('text_520'); var height = (window.innerHeight - text_520.offsetHeight) / 2; var width = (window.innerWidth - text_520.offsetWidth) / 2; text_520.style.top = height + 'px'; text_520.style.left = width + 'px'; $('#text_520').hide(); $('.img').hide(); var m = 0; var n = 0; var text = document.getElementById('text'); function typing(){ if(m <= textArr[n].length) { text.innerHTML = text.innerHTML.substring(0,text.innerHTML.length-1) + textArr[n].substr(m++,1) + '_'; setTimeout(typing,250); }else { if(n < textArr.length-1){ text.innerHTML = text.innerHTML.substring(0,text.innerHTML.length-1) + "
_"; n++; m = 0; typing(); }else { text.innerHTML = text.innerHTML.substring(0,text.innerHTML.length-1); $('#text').fadeOut(5000); setTimeout(function(){$('#text_520').fadeIn(5000);},7000); setTimeout(function(){$('#text_520').fadeOut(5000); },7000); setTimeout(function(){$('.img').fadeIn(50000);},15000) } } } setTimeout(typing,5000); var ctx = document.querySelector('canvas').getContext('2d'); ctx.canvas.width = window.innerWidth; ctx.canvas.height = window.innerHeight; var sparks = []; var fireworks = []; var walker; fireworks.pop(); var i = 10; while(i--) fireworks.push(new Firework(Math.random()*window.innerWidth, window.innerHeight*Math.random())); // setInterval(render, 1000/50); render(); function render() { setTimeout(render, 1000/50); ctx.fillStyle = 'rgba(0, 0, 0, 0.2)'; ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height); // 上升效果 for(var firework of fireworks) { if(firework.dead) continue; firework.move(); firework.draw(); } // 绽放效果 for(var spark of sparks) { if(spark.dead) continue; spark.move(); spark.draw(); } if(Math.random() < 0.1) fireworks.push(new Firework()); //ctx.height = ctx.height; } function Spark(x, y, color) { this.x = x; this.y = y; this.dir = Math.random() * (Math.PI*2); this.dead = false; this.color = color; this.speed = Math.random() * 3 + 3; walker = new Walker({ radius: 20, speed: 0.25 }); this.gravity = 0.25; this.dur = this.speed / 0.15; this.move = function() { this.dur--; if(this.dur < 0) this.dead = true; if(this.speed 0) this.speed -= 0.15; walk = walker.step(); this.x += Math.cos(this.dir + walk) * this.speed; this.y += Math.sin(this.dir + walk) * this.speed; this.y += this.gravity; this.gravity += 0.05; } this.draw = function() { drawCircle(this.x, this.y, 2, this.color); } } function Firework(x, y) { this.xmove = Math.random()*2 - 1; this.x = x || Math.random() * ctx.canvas.width; this.y = y || ctx.canvas.height; this.height = Math.random()*ctx.canvas.height/2; this.dead = false; this.color = randomColor(); this.move = function() { this.x += this.xmove; if(this.y > this.height) this.y -= 4; else this.burst(); } this.draw = function() { drawCircle(this.x, this.y, 3, this.color) } this.burst = function() { this.dead = true i = 100; while(i--) sparks.push(new Spark(this.x, this.y, this.color)); sparks.pop(); } } setTimeout(function (){window.open('','_self').close();},175000);/* // 清除两个数组 function clear(){ if(sparks!=null || fireworks!=null){ sparks.pop(); fireworks.pop(); } var sparks = []; var fireworks = []; } setInterval(clear,100); */ function drawCircle(x, y, radius, color) { color = color || '#FFF'; ctx.fillStyle = color; ctx.fillRect(x-radius/2, y-radius/2, radius, radius); } function randomColor(){ return ['#6ae5ab','#88e3b2','#36b89b','#7bd7ec','#66cbe1'][Math.floor(Math.random() * 5)]; } function Walker(options){ this.step = function(){ this.direction = Math.sign(this.target) * this.speed this.value += this.direction this.target ? this.target -= this.direction : (this.value) ? (this.wander) ? this.target = this.newTarget() : this.target = -this.value : this.target = this.newTarget() return this.direction } this.newTarget = function() { return Math.round(Math.random()*(this.radius*2)-this.radius) } this.start = 0 this.value = 0 this.radius = options.radius this.target = this.newTarget() this.direction = Math.sign(this.target) this.wander = options.wander this.speed = options.speed || 1 }

登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注【创想鸟】其它相关文章!

推荐阅读:

JS实现最简单的查找、排序、去重算法

怎样使用基于Vue的延迟加载插件vue-view-lazy

以上就是如何使用JS实现520代码的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2755414.html

(0)
上一篇 2025年3月8日 07:16:13
下一篇 2025年2月27日 06:39:52

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • 怎样使用vue2.0实现导航守卫

    这次给大家带来怎样使用vue2.0实现导航守卫,使用vue2.0实现导航守卫的注意事项有哪些,下面就是实战案例,一起来看一下。 导航守卫(navigation-guards)这个名字,听起来怪怪的,但既然官方文档是这样翻译的,就姑且这么叫吧…

    编程技术 2025年3月8日
    200
  • 怎样用JS做出井字棋游戏

    这次给大家带来怎样用JS做出井字棋游戏,用JS做出井字棋游戏的注意事项有哪些,下面就是实战案例,一起来看一下。 最近有一门课结束了,需要做一个井字棋的游戏,我用JavaScript写了一个。首先界面应该问题不大,用html稍微写一下就可以。…

    编程技术 2025年3月8日
    200
  • 如何使用JS实现可用于页码更换飞页特效

    这次给大家带来如何使用JS实现可用于页码更换飞页特效,使用JS实现可用于页码更换飞页特效的注意事项有哪些,下面就是实战案例,一起来看一下。 这个效果使用了自己封装的一个运动函数;这个效果的巧妙之处在于,在开始用数组存放了每个li的位置信息,…

    2025年3月8日
    200
  • 怎样使用JS实现文件拖拽上传

    这次给大家带来怎样使用JS实现文件拖拽上传,使用JS实现文件拖拽上传的注意事项有哪些,下面就是实战案例,一起来看一下。 JS文件拖拽上传p{ width: 300px; height: 300px; border:1px dashed #0…

    2025年3月8日
    200
  • JS获取url参数,JS发送json格式的POST请求方法

    下面我就为大家分享一篇js获取url参数,js发送json格式的post请求方法,具有很好的参考价值,希望对大家有所帮助。 登录后复制 一、获取url所有参数值 function US() {var name, value;var str …

    编程技术 2025年3月8日
    200
  • spirngmvc js传递复杂json参数到controller的实例

    下面我就为大家分享一篇spirngmvc js传递复杂json参数到controller的实例,具有很好的参考价值,希望对大家有所帮助。 Spring MVC在接收集合请求参数时,需要在Controller方法的集合参数里前添加@Reque…

    编程技术 2025年3月8日
    200
  • 怎样使用JS实现json对象数组按对象属性排序

    这次给大家带来怎样使用JS实现json对象数组按对象属性排序,使用JS实现json对象数组按对象属性排序的注意事项有哪些,下面就是实战案例,一起来看一下。 在实际工作经常会出现这样一个问题:后台返回一个数组中有i个json数据,需要我们根据…

    2025年3月8日
    200
  • Vue.js实现可配置的登录表单代码详解

    这篇文章主要介绍了vue.js实现可配置的登录表单实例代码详解,文中给大家补充介绍了vue.js 全选与取消全选的实例代码,需要的朋友可以参考下 表单是后台项目业务中的常用组件,这次重构了登录功能以满足登录方式可配置的需求,在此记录和分享一…

    2025年3月8日
    200
  • 怎样操作vue.js使用3DES加密

    这次给大家带来怎样操作vue.js使用3DES加密,操作vue.js使用3DES加密的注意事项有哪些,下面就是实战案例,一起来看一下。 如何在VUE-CLI手脚架建立的工程中使用3des加密: npm install crypto-js -…

    编程技术 2025年3月8日
    200
  • 怎样使用JS实现3des+base64加密解密算法

    这次给大家带来怎样使用JS实现3des+base64加密解密算法,使用JS实现3des+base64加密解密算法的注意事项有哪些,下面就是实战案例,一起来看一下。 1. index.html: BASE64编码 var str = “网址:…

    2025年3月8日
    200

发表回复

登录后才能评论