亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery+vue.js實現的九宮格拼圖游戲完整實例【附源碼下載】

 更新時間:2017年09月12日 11:25:30   作者:ITzhongzi  
這篇文章主要介紹了jQuery+vue.js實現的九宮格拼圖游戲,結合完整實例形式分析了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.jb51.net/games/pintu

在線圖片添加/解密隱藏信息(隱寫術)工具:
http://tools.jb51.net/aideddesign/img_add_info

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery圖片操作技巧大全》、《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常用插件及用法總結》、《jQuery常見經典特效匯總》及《jquery選擇器用法總結

希望本文所述對大家jQuery程序設計有所幫助。

相關文章

  • jQuery實現上下滾動公告欄詳細代碼

    jQuery實現上下滾動公告欄詳細代碼

    之前做項目的時候,一直都想著做一個上下滾動的公告欄,作為展示網站的最新公告信息,給用戶帶來極好的用戶體驗,下面小編通過實例代碼給大家分享基于jQuery實現上下滾動公告欄,感興趣的朋友一起看看吧
    2018-11-11
  • jQuery插件EasyUI實現Layout框架頁面中彈出窗體到最頂層效果(穿越iframe)

    jQuery插件EasyUI實現Layout框架頁面中彈出窗體到最頂層效果(穿越iframe)

    這篇文章主要介紹了jQuery插件EasyUI實現Layout框架頁面中彈出窗體到最頂層效果,具有穿越iframe的功能,涉及jQuery的EasyUI插件屬性操作相關技巧,需要的朋友可以參考下
    2016-08-08
  • JQuery中的$.getJSON 使用說明

    JQuery中的$.getJSON 使用說明

    jQuery中常用getJSON來調用并獲取遠程的JSON字符串,將其轉換為JSON對象,如果成功,則執(zhí)行回調函數。
    2011-03-03
  • jQuery制作圣誕主題頁面 更像是愛情影集

    jQuery制作圣誕主題頁面 更像是愛情影集

    這篇文章主要為大家詳細介紹了jQuery制作圣誕主題頁面的方法,類似動感影集,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-08-08
  • jQuery中removeProp()方法用法實例

    jQuery中removeProp()方法用法實例

    這篇文章主要介紹了jQuery中removeProp()方法用法,實例分析了removeProp()方法的功能、定義及刪除由prop()方法設置的屬性時的使用技巧,需要的朋友可以參考下
    2015-01-01
  • jQuery焦點圖輪播插件KinSlideshow用法分析

    jQuery焦點圖輪播插件KinSlideshow用法分析

    這篇文章主要介紹了jQuery焦點圖輪播插件KinSlideshow用法,結合實例形式較為詳細的分析了jQuery焦點圖輪播插件KinSlideshow的參數含義與使用方法,需要的朋友可以參考下
    2016-06-06
  • 通過pjax實現無刷新翻頁(兼容新版jquery)

    通過pjax實現無刷新翻頁(兼容新版jquery)

    這篇文章主要介紹了通過pjax實現無刷新翻頁,兼容新版jquery,使用心得方法,需要的朋友可以參考下
    2014-01-01
  • jquery 問答知識整理

    jquery 問答知識整理

    jquery 問答知識整理,學習jquery的朋友可以參考下。
    2010-02-02
  • jQuery簡單實現MD5加密的方法

    jQuery簡單實現MD5加密的方法

    這篇文章主要介紹了jQuery簡單實現MD5加密的方法,基于jquery.md5.js插件實現md5加密功能,非常簡單實用,需要的朋友可以參考下
    2017-03-03
  • jquery獲取復選框checkbox的值實現方法

    jquery獲取復選框checkbox的值實現方法

    下面小編就為大家?guī)硪黄猨query獲取復選框checkbox的值實現方法。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-05-05

最新評論