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>
  • 相关阅读:
    dom4j解析xml字符串实例
    使用Dom4j生成xml文件(utf-8编码)
    viewer.js插件简单使用说明
    html标签title属性效果优化
    XML文件读写编码不是UTF-8的问题
    webservice wsdl文件标签讲解
    定销房概念扫盲
    Sql Server系列:视图
    Centos7安装mysql5.6
    java实现链式队列
  • 原文地址:https://www.cnblogs.com/xingmeng/p/2889416.html
Copyright © 2011-2022 走看看