全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

jQuery+vue.js实现的九宫格拼图游戏完整实例【附源码下载】

本文实例讲述了jQuery+vue.js实现的九宫格拼图游戏。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    /*#piclist {
      width: 600px;
      height: 600px;
      background-color: green;
    }*/
    .nitem {
      /*width: 200px;*/
      /*height: 200px;*/
      float: left;
      background: url(img/meinv.jpg) 0px 0px no-repeat;
      -webkit-background-size: 600px 600px;
      background-size: 600px 600px;
      font-size: 33px;
      color: red;
      font-weight: bold;
      cursor: pointer;
    }
    /*.nitem:nth-child(2){
      background-position: -200px 0;
    }
    .nitem:nth-child(3){
      background-position: -400px 0;
    }
    .nitem:nth-child(4){
      background-position: 0px -200px;
    }
    .nitem:nth-child(5){
      background-position: -200px -200px;
    }
    .nitem:nth-child(6){
      background-position: -400px -200px;
    }
    .nitem:nth-child(7){
      background-position: 0px -400px;
    }
    .nitem:nth-child(8){
      background-position: -200px -400px;
    }
    .nitem:nth-child(9){
      background-position: -400px -400px;
    }*/
    .fn-clear {
      clear: both;
      height: 0;
      line-height: 0px;
      font-size: 0px;
    }
  </style>
</head>
<body>
<div id="appbox" :style="{ width:width+'px',height:height+'px' }">
  <div id="piclist">
    <div class="nitem"
       v-for="(item,index) in itemlist"
       :class="{remove : index === 0}"
       :index="index "
       v-bind:style="{
        'backgroundPosition':-px(index)+'px -' + py(index) + 'px',
         width : width / rows + 'px',
         height : height / cols + 'px'}">{{index}}
    </div>
  </div>
</div>
</body>
<script src=js/jquery-1.9.1.min.js></script>
<script src=js/vue.min.js></script>
<script>
  var olen = 0, oi = 0, cindex = 0, oa = new Array(), oindex = 0, listarray = new Array();
  var vm = new Vue({
    el: "#appbox",
    data: {
      itemlist: [],
      rows: 3,
      cols: 3,
      width: 600,
      height: 600,
    },
    methods: {
      px(index){
        return (index % this.rows) * (this.width / this.rows)
      },
      py (index){
        return parseInt((index / this.cols)) * (this.height / this.cols);
      }
    }
  });
  for (var i = 0; i < vm.rows * vm.cols; i++) {
    vm.itemlist.push(i);
  }
  function getrow(index) {
    return parseInt(index / vm.cols);
  }
  function getcols(index) {
    return index % vm.rows;
  }
  function getBound(index) {
    var left = index - 1;
    var right = index + 1;
    var top = index - vm.rows;
    var bottom = index + vm.rows;
    var len = vm.itemlist.length; //总长度
    var currentRow = getrow(index);
    var currentCol = getcols(index);
    var roundArr = new Array();
    if (left >= 0 && left < len && getrow(left) == currentRow) {
      roundArr.push(left);
    }
    if (right >= 0 && right < len && getrow(right) == currentRow) {
      roundArr.push(right);
    }
    if (top >= 0 && top < len && getcols(top) == currentCol) {
      roundArr.push(top);
    }
    if (bottom >= 0 && bottom < len && getcols(bottom) == currentCol) {
      roundArr.push(bottom);
    }
    return roundArr;
  }
  function box_switch(i, j) {
    var iobj = $('#piclist .nitem').eq(i);
    var jobj = $('#piclist .nitem').eq(j);
    var tobj = iobj.clone();
    jobj.after(tobj);
    iobj.replaceWith(jobj);
  }
  vm.$nextTick(function () {
    $('.remove').css({
      background: 'none',
      backgroundColor: 'green'
    });
  });
  function box_rand(times) {
    for (var i = 0; i < times; i++) {
      oindex = $('.remove').index();
      oa = getBound(oindex);
      olen = oa.length;
      oi = Math.floor(Math.random() * olen);
      cindex = oa[oi];
      box_switch(cindex, oindex);
    }
    listarray.length = 0;
    $.each($('.nitem'), function (i, item) {
      listarray.push($(item).attr('index'));
    });
    if (listarray.join(',') == vm.itemlist.join(',')) {
      box_rand(times);
    }
  }
  $(function () {
    //打乱图片
    box_rand(20);
    $('.nitem').on('click  ', function () {
      var cindex = $(this).index();
      var oindex = $('.remove').index();
      var oRound = getBound(oindex); //空盒子四周的索引
      if ($.inArray(cindex, oRound) < 0) { //不在
        return false;
      } else {
        box_switch(oindex, cindex);
        var listArray = new Array();
        $.each($('.nitem'), function (i, item) {
          listArray.push($(item).attr('index'));
        })
        if (listArray.join(',') == vm.itemlist.join(',')) {
          alert('success')
        } else {
          console.log('失败')
        }
      }
    });
  })
</script>
</html>

附:完整实例代码点击此处本站下载

PS:这里再为大家推荐两款相关图片类工具供大家参考:

在线|美女|拼图游戏:
http://tools./games/pintu

在线图片添加/解密隐藏信息(隐写术)工具:
http://tools./aideddesign/img_add_info

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery图片操作技巧大全》、《jQuery表格(table)操作技巧汇总》、《jQuery切换特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery常见经典特效汇总》及《jquery选择器用法总结》

希望本文所述对大家jQuery程序设计有所帮助。


# jQuery  # vue.js  # 九宫格  # 拼图  # 游戏  # JS快速实现移动端拼图游戏  # JS 拼图游戏 面向对象  # 注释完整。  # js+html5实现可在手机上玩的拼图游戏  # JS实现拼图游戏  # 基于javascript制作经典传统的拼图游戏  # 基于Vue.js实现数字拼图游戏  # 利用原生的JavaScript实现简单拼图游戏  # javascript结合Flexbox简单实现滑动拼图游戏  # 基于JS实现简单滑块拼图游戏  # 使用js编写实现拼图游戏  # 操作技巧  # 拼图游戏  # 相关内容  # 相关图片  # 感兴趣  # 给大家  # 点击此处  # 两款  # 更多关于  # 所述  # 程序设计  # 再为  # 总长度  # 选择器  # 讲述了  # weight  # bold  # red  # nth 


相关文章: 建站主机SSH密钥生成步骤及常见问题解答?  制作假网页,招聘网的薪资待遇,会有靠谱的吗?一面试又各种折扣?  高防网站服务器:DDoS防御与BGP线路的AI智能防护方案  建站之星免费版是否永久可用?  清单制作人网站有哪些,近日“兴风作浪的姑奶奶”引起很多人的关注这是什么事情?  定制建站如何定义?其核心优势是什么?  TestNG的testng.xml配置文件怎么写  已有域名如何免费搭建网站?  建站一年半SEO优化实战指南:核心词挖掘与长尾流量提升策略  如何在局域网内绑定自建网站域名?  定制建站流程步骤详解:一站式方案设计与开发指南  如何通过远程VPS快速搭建个人网站?  如何在Windows 2008云服务器安全搭建网站?  网站制作哪家好,cc、.co、.cm哪个域名更适合做网站?  如何用景安虚拟主机手机版绑定域名建站?  网站制作员失业,怎样查看自己网站的注册者?  招商网站制作流程,网站招商广告语?  深圳网站制作费用多少钱,读秀,深圳文献港这样的网站很多只提供网上试读,但有些人只要提供试读的文章就能全篇下载,这个是怎么弄的?  企业微网站怎么做,公司网站和公众号有什么区别?  如何设计高效校园网站?  内网网站制作软件,内网的网站如何发布到外网?  宝塔建站助手安装配置与建站模板使用全流程解析  开源网站制作软件,开源网站什么意思?  黑客如何利用漏洞与弱口令入侵网站服务器?  如何通过二级域名建站提升品牌影响力?  建站之星后台密码遗忘?如何快速找回?  如何快速使用云服务器搭建个人网站?  如何在Golang中指定模块版本_使用go.mod控制版本号  网站好制作吗知乎,网站开发好学吗?有什么技巧?  深圳网站制作设计招聘,关于服装设计的流行趋势,哪里的资料比较全面?  建站之星后台密码遗忘或太弱?如何重置与强化?  七夕网站制作视频,七夕大促活动怎么报名?  如何挑选高效建站主机与优质域名?  网站制作网站,深圳做网站哪家比较好?  山东网站制作公司有哪些,山东大源集团官网?  ,网页ppt怎么弄成自己的ppt?  佛山企业网站制作公司有哪些,沟通100网上服务官网?  公司门户网站制作流程,华为官网怎么做?  佛山网站制作系统,佛山企业变更地址网上办理步骤?  如何在云主机快速搭建网站站点?  广州网站建站公司选择指南:建站流程与SEO优化关键词解析  南平网站制作公司,2025年南平市事业单位报名时间?  宝塔Windows建站如何避免显示默认IIS页面?  高端企业智能建站程序:SEO优化与响应式模板定制开发  已有域名能否直接搭建网站?  如何在景安云服务器上绑定域名并配置虚拟主机?  ,石家庄四十八中学官网?  小建面朝正北,A点实际方位是否存在偏差?  天河区网站制作公司,广州天河区如何办理身份证?需要什么资料有预约的网站吗?  如何在Golang中引入测试模块_Golang测试包导入与使用实践 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。