zoukankan      html  css  js  c++  java
  • 简单的拼图游戏

    百度上看到有人求下图效果,我简单作了一下,分享到这里:

    我的图:

    代码如下:

    <style type="text/css">
    #box,#box2{width:310px;height:310px; position:relative;}
    #box span{ position:absolute; border:2px solid #fff; display:block; width:100px;height:100px; background:#aaa; font-size:50px; line-height:100px; text-align:center;}
    #box span.on{ border:2px solid red}
    #box2 span{ position:absolute; border:2px solid #fff; display:block; width:100px;height:100px; background:#ddd; font-size:50px; line-height:100px; text-align:center;}
    #box2 span.on{ border:2px solid #F60}
    </style>
    
    <div id="box">
    </div>
    
    <div id="box2">
    </div>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript">
    jQuery(function(){
        for(i=0;i<9;i++){
            $('#box').append('<span></span>')
            $('#box2').append('<span></span>')
        }
        
        $('#box span').each(function(index) {
            var t=parseInt(index/3); 
            var l=index%3;
            $(this).css({'left':l*104,'top':t*104});
            $(this).text(index+1)
            $(this).click(function(){
                $('#box span.on').removeClass('on')
                $(this).addClass('on');
            })
        });
        $('#box2 span').each(function(index) {
            var t=parseInt(index/3); 
            var l=index%3;
            $(this).css({'left':l*104,'top':t*104});
            
            $(this).click(function(){
                $('#box2 span.on').removeClass('on');
                $(this).addClass('on');
                $(this).text($('#box span.on').text())
                $('#box span.on').hide();
            })
        });
    })
    </script>
  • 相关阅读:
    XMLHttpRequest对象垃圾回收
    Stored XSS攻击
    重写setTimeout
    js instanceof Object Function
    maven的环境搭建
    Struts2整合json
    分页框架(Pager-taglib)的使用及sitemesh的简单使用
    首页文章标题分页
    在线HTML编辑器的引入
    Sparse PCA: reproduction of the synthetic example
  • 原文地址:https://www.cnblogs.com/cssfirefly/p/2958131.html
Copyright © 2011-2022 走看看