jQuery实现简单的打字游戏功能

来源:互联网 发布:紧急通知网页域名升级 编辑:程序博客网 时间:2024/05/22 09:41
css:<style>*{padding:0px;margin:0px}#main{width:1000px;height:600px;}.div{width:20px;line-height:0px}</style>jQuery:<script>    $(function(){var i=1;var zd;function show(){clearTimeout(a);var zm=parseInt(Math.random()*25);zd=String.fromCharCode(zm+65);var wy=Math.random()*500;//设置偏移量var a=setTimeout(show,1000);$("#main").append($("<div class='div' name='"+zd+"' id='a"+i+"'>"+zd+"</div>"));$("div[id='a"+i+++"']").offset({ top: 0, left: wy}).animate({top:600},10000,function() {$(this).remove();});}show();$(window).keydown(function(event){  var value=event.keyCode;var re=String.fromCharCode(value);if(re!=null){$("div[name='"+re+"']").remove();}});})    </script>
不加line-height:0px,会导致字母消失时,其他的字母向上回升


原创粉丝点击