zoukankan      html  css  js  c++  java
  • js生成动态的飘过效果

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="js/jquery.min.js" ></script>
    <script type="text/javascript">
    // 初始化
    var _pos = 0; // 初始位置
    var _direcation = 1; // 初始方向,1为x+方向,-1为x-方向
    var _x = 5; // 最大宽度
    var _y = 40; // 最大高度
     
    // 动态更新
    function update(){
    var pos = _pos; // 当前位置
    var direcation = _direcation; // 当前方向
    var output = '';
     
    for(var i=0; i<_y; i++){
    output += '<div>' + rp('.',pos) + '飘过</div>';
    if((pos<=0&&direcation<=0)||(pos>=_x&&direcation>=0))
    direcation *= -1; // 更新方向
    pos += direcation * 1; // 更新位置
    }
    $('#happy').html(output);
     
    // 更新初始数据
    if((_pos<=0&&_direcation<=0)||(_pos>=_x&&_direcation>=0))
    _direcation *= -1; // 更新方向
    _pos += _direcation * 1; // 更新位置
    }
     
    // 重复输出字符串N次
    function rp(str,len){
    //if(!len&&len!==0) len += 2;
    return new Array(len+1).join(str);
    }
    </script>
    <style type="text/css">
    body,html{font-size:12px; letter-spacing: 0.2em;}
    div{margin:5px 20px;}
    </style>
    </head>
    <body>
    <div id="happy"></div>
    <script type="text/javascript">
    setInterval('update()',80);
    </script>
    </body>
    </html>
  • 相关阅读:
    以太坊客户端Geth命令用法
    ubuntu 下载地址
    以太坊(二)安装Solidity编译器
    git 查看&修改用户名
    以太坊(一)
    centos7 时间设置
    centos7 桥接配置
    nginx http转 https
    centOS7 安装mysql5.7
    webpack--关于babel的配置
  • 原文地址:https://www.cnblogs.com/xingmeng/p/2889416.html
Copyright © 2011-2022 走看看