如何编写电脑代码雨?

html-css013

如何编写电脑代码雨?,第1张

代码雨就是代码数字不断的刷新,这个效果可以通过几句简单的程序来实现,具体方法如下:

1、电脑用户在自己的电脑桌面上创建一个文本文件。创建以后打开。

2、打开以后,在文件中输入代码。代码如下图所示。

3、完成代码雨的代码编写以后,点击工具栏中的文件。然后在点击另存为。

4、点击另存为以后,将下方的文件名的后缀改为“.bat”。文件名用户随意定义。修改好以后点击“保存”。

5、完成文件的编写和保存以后,右击文件点击以管理员身份运行。

6、运行效果如下。

注意事项:

1、代码不用写错,写错不能运行。

2、在另存的时候,如果不显示后缀,将保持文件选成“所有文件”,在文件名称后面直接打.bat即可。

<style>

* {

margin:0

padding:0

}

body {

background:black

overflow:hidden

}

.container {

width:20px

height:60px

position:absolute

}

.nav {

height:20px

width:20px

display:block

margin-top:12px

border-radius:10px

background:#33ccff

opacity:0.8

background: url(1.jpg) no-repeat center

background-size: auto 100%

}

</style>

<script>

$(function() {

var w = window.screen.width

var h = window.screen.height

var count = 0

var drop = function() {

this.v = Math.random() * 1 + 0.5

this.left = Math.random() * w

}

drop.prototype = {

constructor: drop,

create: function() {

count++

var $drop = $('<div class="container"><span class="nav"></span></div>')

$drop.appendTo('body')

},

addCss: function() {

$('.container:last').css({

left: this.left + 'px'

})

},

dropEvent: function() {

var time = Math.floor(h / this.v)//下降速度

$('.container:last').animate({

top: h + 'px',

opacity: '1'

}, time)

}

}

function updata() {

if(count >200) {

for(var i = 0i <100i++) {

$('div:first').remove()

}

count = 0

}

}

setInterval(function() {

var Drop = new drop()

Drop.create()

Drop.addCss()

Drop.dropEvent()

updata()

}, 50)

})

</script>