前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >简单的拼图游戏

简单的拼图游戏

作者头像
deepcc
发布2018-05-16 14:41:09
1.2K0
发布2018-05-16 14:41:09
举报
文章被收录于专栏:deepcc

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

我的图:

代码如下:

代码语言:javascript
复制
<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>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2013-03-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档