• 会飞的小鸟


    html:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link href="css/demo1.css" rel="stylesheet" />
    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/demo1.js"></script>
    </head>
    <body>
    <div id="dbird"><img src="img/bird.gif"></div>
    </body>
    </html>

    css:

    *{
    padding:0px;
    margin:0px;

    }
    #dbird{
    206px;
    height:121px;
    position:absolute;
    }
    body {
    overflow:hidden;
    }

    .driection-37{
    transform:rotateY(180deg);
    }
    .driection-38{
    transform:rotate(-60deg);
    }
    .driection-40{
    transform:rotate(60deg);
    }

    js:

    /// <reference path="jquery-1.10.2.min.js" />
    var step = 10;//步值
    var rcode = 39;
    $(function () {
    var off = $("#dbird").offset();//获取小鸟当前的方位
    var dwidth = $(window).width();//获取浏览的宽度和高度
    var dheight = $(window).height();
    var bwidth = $("#dbird").width();//获取小鸟的宽度和高度
    var bheight = $("#dbird").height();

    $(document).keydown(function (e) {
    var keycode = e.keyCode;
    if (keycode != rcode) {
    $("#dbird").removeClass().addClass("driection-" + keycode);
    }
    rcode = keycode;
    //alert(keycode);
    switch (keycode) {
    case 37://左边
    off.left -= step;
    if (off.left <= -bwidth) {
    off.left = dwidth;
    }
    break;
    case 38://上
    off.top -= step;
    if (off.top <= -bheight) {
    off.top = dheight;
    }
    break;

    case 39://右
    off.left += step;
    if (off.left >= dwidth) {
    off.left = -bwidth;
    }
    break;
    case 40://下
    off.top += step;
    if (off.top >= dheight) {
    off.top = -bheight;
    }
    break;
    }
    $("#dbird").offset(off);
    });

    });

  • 相关阅读:
    解惑开源项目协作流程
    结合webpack 一步一步实现懒加载的国际化简易版方案
    SEO优化之——hreflang(多语言网站优化)
    pandas数据分析常用
    多任务: 多进程与多线程
    linux基础知识
    python常用模块之sys, os, random
    递归函数(初级难点)
    内置函数
    函数
  • 原文地址:https://www.cnblogs.com/sunshinezjb/p/8550425.html
Copyright © 2020-2023  润新知