jquery實現(xiàn)的美女拼圖游戲?qū)嵗?/h1>
更新時間:2015年05月04日 17:15:56 投稿:shichen2014
這篇文章主要介紹了jquery實現(xiàn)的美女拼圖游戲,實例分析了jQuery操作圖片的相關(guān)技巧,需要的朋友可以參考下
本文實例講述了jquery實現(xiàn)的美女拼圖游戲。分享給大家供大家參考。具體如下:
這里可以自由打亂拼圖次序,3*3,4*4等多種組合來進(jìn)行格數(shù)拼圖
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jquery-puzzle by 4074</title>
<style>
html{
height:100%;
}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,button,textarea,p,blockquote,th,td{
padding:0;
margin:0;
}
body{
font-family: "Helvetica Neue", "Hiragino Sans GB", "Segoe UI", "Microsoft Yahei", "微軟雅黑", Tahoma, Arial, STHeiti, sans-serif;
font-size:12px;
background:#fff;
color:#333;
}
a{
outline:none;
-moz-outline:none;
text-decoration:none;
}
.clearfix{
zoom:1;
_height:1px;
}
.clearfix:after{
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.head{
height:50px;
line-height:50px;
padding-left:20px;
border-bottom:1px solid #eee;
box-shadow: 1px 1px 5px #ccc;
}
.head h1{
float:left;
width:320px;
font-weight:normal;
font-size:22px;
}
.head span{
display:block;
float:right;
font-size:12px;
color:#999;
line-height:14px;
margin:30px 10px 0 0;
}
.wrap{
width:1000px;
margin:80px auto;
}
.play_wrap{
width:300px;
float:left;
padding:20px;
margin-left:200px;
}
#play_area{
position:relative;
width:300px;
height:300px;
margin:auto;
background:#fefefe;
border-radius:2px;
color: black;
box-shadow: 0px 0px 8px #09F;
border:1px solid #fff;
*border:1px solid #e5e5e5;
cursor:default;
}
#play_area .play_cell{
width:48px;
height:48px;
border:1px solid #fff;
border-radius:4px;
position:absolute;
background-position: 5px 5px;
cursor: default;
z-index:80;
box-shadow:0px 0px 8px #fff;
transition-property:background-position;
transition-duration:300ms;
transition-timing-function:ease-in-out;
}
#play_area .play_cell.hover{
filter: alpha(opacity=80);
opacity:.8;
box-shadow: 0px 0px 8px #000;
z-index:90;
*border:1px solid #09F;
}
.play_menu{
float:left;
margin-left:60px;
font-size:14px;
padding-top:20px;
}
.play_menu p{
line-height:200%;
clear:both;
}
.play_menu a.play_btn{
display:block;
margin-bottom:20px;
width:80px;
height:28px;
line-height:28px;
text-align:center;
text-decoration:none;
color:#333;
background:#fefefe;
border:1px solid #eee;
border-radius: 2px;
box-shadow: 1px 1px 2px #eee;
border-color: #ddd #d2d2d2 #d2d2d2 #ddd;
outline:none;
-moz-outline:none;
}
.play_menu a.play_btn:hover{
background-color: #fcfcfc;
border-color: #ccc;
box-shadow: inset 0 -2px 6px #eee;
}
.play_menu a#play_btn_level{
position:relative;
margin-bottom:30px;
}
.level_text{
margin-left:-10px;
}
.level_icon{
display:block;
position:absolute;
top:12px;
right:16px;
width:0;
height:0;
overflow:hidden;
border:5px solid #FFF;
border-color:#999 transparent transparent transparent;
}
.level_menu{
position:absolute;
margin:-30px 0 0px 1px;
display:none;
}
.level_menu ul{
list-style:none;
}
.level_menu li{
float:left;
}
.level_menu li a{
display:block;
padding:3px 10px;
border:1px solid #e8e8e8;
margin-left:-1px;
color:#09c;
}
.level_menu li a:hover{
background:#09c;
color:#fefefe;
}
#info{
font-size:16px;
margin:30px 0 0 0;
}
#info a{
color:#09F;
}
</style>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
var puzzleGame = function(options){
this.img = options.img || "";
this.e_playArea = $("#play_area");
this.e_startBtn = $("#play_btn_start");
this.e_playScore = $("#play_score");
this.e_playCount = $("#play_count");
this.e_levelBtn = $("#play_btn_level");
this.e_levelMenu = $("#play_menu_level");
this.areaWidth = parseInt(this.e_playArea.css("width"));
this.areaHeight = parseInt(this.e_playArea.css("height"));
this.offX = this.e_playArea.offset().left;
this.offY = this.e_playArea.offset().top;
this.levelArr = [[3,3],[4,4],[6,6]];
this.level = 1;
this.scoreArr = [100,200,400];
this.score = 0;
this.playCount = 0;
this.cellRow = this.levelArr[this.level][0];
this.cellCol = this.levelArr[this.level][1];
this.cellWidth = this.areaWidth/this.cellCol;
this.cellHeight = this.areaHeight/this.cellRow;
this.imgArr = [];
this.ranArr = [];
this.cellArr = [];
this.easing = 'swing';
this.time = 400;
this.thisLeft = 0;
this.thisTop = 0;
this.nextIndex;
this.thisIndex;
this.cb_cellDown = $.Callbacks();
this.isInit = false;
this.isBind = false;
this.start();
};
puzzleGame.prototype = {
start:function(){
this.init();
this.menu();
},
set: function(options){
this.level = options.level === 0 ? 0 : (options.level || 1);
},
menu:function(){
var self = this;
this.e_startBtn.click(function(){
self.e_levelMenu.hide();
self.play();
});
this.e_levelBtn.click(function(){
if(self.playing) return;
self.e_levelMenu.toggle();
});
this.e_levelMenu.find("a").click(function(){
self.e_levelMenu.hide();
self.e_levelBtn.find(".level_text").html($(this).html())
if(parseInt($(this).attr("level")) !== self.level){
self.set({
"level": $(this).attr("level")
});
self.isInit = true;
self.isBind = false;
}
})
},
play:function(){
if(this.isInit){
this.isInit = false;
this.cellRow = this.levelArr[this.level][0];
this.cellCol = this.levelArr[this.level][1];
this.cellWidth = this.areaWidth/this.cellCol;
this.cellHeight = this.areaHeight/this.cellRow;
this.init();
}
this.e_playCount.html(this.playCount = 0);
this.randomImg();
if(!this.isBind)this.bindCell();
},
init:function(){
var _cell;
this.cellArr = [];
this.imgArr = [];
this.e_playArea.html("");
for(var i = 0; i<this.cellRow; i++){
for(var j = 0; j<this.cellCol; j++){
this.imgArr.push(i*this.cellCol + j);
_cell = document.createElement("div");
_cell.className = "play_cell";
$(_cell).css({
"width": this.cellWidth-2,
"height": this.cellHeight-2,
"left": j * this.cellWidth,
"top": i * this.cellHeight,
"background": "url(" + this.img + ")",
"backgroundPosition": (-j) * this.cellWidth + "px " + (-i) * this.cellHeight + "px"
});
this.cellArr.push($(_cell));
this.e_playArea.append(_cell);
}
}
},
randomImg:function(){
var ran,arr;
arr = this.imgArr.slice();
this.ranArr = [];
for(var i = 0, ilen = arr.length; i < ilen; i++){
ran = Math.floor(Math.random() * arr.length);
this.ranArr.push(arr[ran]);
this.cellArr[i].css({
"backgroundPosition": (-arr[ran]%this.cellCol) * this.cellWidth + "px " + (-Math.floor(arr[ran]/this.cellCol)) * this.cellHeight + "px"
})
arr.splice(ran,1);
}
$("#p").html(this.ranArr.join())
},
bindCell:function(){
var self = this;
this.isBind = true;
this.cb_cellDown.add(self.cellDown);
for(var i = 0, len = this.cellArr.length; i<len; i++){
this.cellArr[i].on({
"mouseover": function(){
$(this).addClass("hover");
},
"mouseout": function(){
$(this).removeClass("hover");
},
"mousedown": function(e){
self.cb_cellDown.fire(e, $(this), self);
return false;
}
});
}
},
cellDown:function(e,_cell,self){
var //self = this,
_x = e.pageX - _cell.offset().left,
_y = e.pageY - _cell.offset().top;
self.thisLeft = _cell.css("left");
self.thisTop = _cell.css("top");
self.thisIndex = Math.floor(parseInt(self.thisTop)/self.cellHeight)*self.cellCol;
self.thisIndex += Math.floor(parseInt(self.thisLeft)/self.cellWidth);
_cell.css("zIndex",99);
$(document).on({
"mousemove": function(e){
_cell.css({
"left": e.pageX - self.offX - _x,
"top": e.pageY - self.offY - _y
})
},
"mouseup": function(e){
$(document).off("mouseup");
$(document).off("mousemove");
self.cb_cellDown.empty();
if( e.pageX - self.offX < 0 || e.pageX - self.offX > self.areaWidth || e.pageY - self.offY < 0 || e.pageY - self.offY > self.areaHeight ){
self.returnCell();
return;
}
var _tx, _ty, _ti, _tj;
_tx = e.pageX - self.offX;
_ty = e.pageY - self.offY;
_ti = Math.floor( _ty / self.cellHeight );
_tj = Math.floor( _tx / self.cellWidth );
self.nextIndex = _ti*self.cellCol + _tj;
if(self.nextIndex == self.thisIndex){
self.returnCell();
}else{
self.changeCell();
}
}
})
},
changeCell:function(){
var self = this,
_tc = this.cellArr[this.thisIndex],
_tl = this.thisLeft,
_tt = this.thisTop,
_nc = this.cellArr[this.nextIndex],
_nl = (this.nextIndex % this.cellCol) * this.cellWidth,
_nt = Math.floor(this.nextIndex / this.cellCol) * this.cellHeight;
_nc.css("zIndex",98);
this.cellArr[this.nextIndex] = _tc;
this.cellArr[this.thisIndex] = _nc;
this.ranArr[this.nextIndex] = this.ranArr[this.nextIndex] + this.ranArr[this.thisIndex];
this.ranArr[this.thisIndex] = this.ranArr[this.nextIndex] - this.ranArr[this.thisIndex];
this.ranArr[this.nextIndex] = this.ranArr[this.nextIndex] - this.ranArr[this.thisIndex];
_tc.animate({
"left": _nl,
"top": _nt
},self.time,self.easing,function(){
_tc.removeClass("hover");
_tc.css("zIndex","");
})
_nc.animate({
"left": _tl,
"top": _tt
},self.time,self.easing,function(){
_nc.removeClass("hover");
_nc.css("zIndex","");
self.check();
if(!self.cb_cellDown.has(self.cellDown)) self.cb_cellDown.add(self.cellDown);
})
},
returnCell:function(){
var self = this;
this.cellArr[this.thisIndex].animate({
"left": self.thisLeft,
"top": self.thisTop
},self.time,self.easing,function(){
$(this).removeClass("hover");
$(this).css("zIndex","");
if(!self.cb_cellDown.has(self.cellDown)) self.cb_cellDown.add(self.cellDown);
});
},
check:function(){
this.e_playCount.html( ++ this.playCount);
if(this.ranArr.join() == this.imgArr.join()){
this.success();
}
},
success:function(){
alert("ok");
this.score += this.scoreArr[this.level]
this.e_playScore.html(this.score);
}
}
$(document).ready(function(e) {
var pg = new puzzleGame({
img: "images/120908-1347075337_M.jpg"
});
});
</script>
</head>
<body>
<div class="wrap">
<div class="play_wrap">
<div id="play_area"></div>
</div>
<div class="play_menu">
<a id="play_btn_start" class="play_btn" href="javascript:void(0);" unselectable="on">開始</a>
<a id="play_btn_level" class="play_btn" href="javascript:void(0);" unselectable="on">
<span class="level_text">4 x 4</span>
<span class="level_icon"></span>
</a>
<div class="level_menu" id="play_menu_level">
<ul>
<li>
<a href="javascript:void(0);" level=0 >3 x 3</a>
</li>
<li>
<a href="javascript:void(0);" level=1 >4 x 4</a>
</li>
<li>
<a href="javascript:void(0);" level=2 >6 x 6</a>
</li>
</ul>
</div>
<p>完成:<span id="play_score">0</span></p>
<p>交換:<span id="play_count">0</span></p>
<p>說明:<br>
-點(diǎn)擊開始,小圖片將隨機(jī)打亂;<br>
-拖動小圖片可交換位置,順序完全正確則為成功;<br>
-難度分“3x3”、“4x4”、“6x6”三級;<br>
-對應(yīng)的分值為100、200、400;
</p>
</div>
</div>
</body>
</html>
希望本文所述對大家的jQuery程序設(shè)計有所幫助。
相關(guān)文章
-
基于jquery的二級聯(lián)動菜單實現(xiàn)代碼
基于jquery的二級聯(lián)動菜單實現(xiàn)代碼,腳本之家簡單整理了幾種。需要的朋友可以參考下,主要是思路 2011-04-04
-
jQuery Easyui datagrid editor為combobox時指定數(shù)據(jù)源實例
當(dāng)在datagrid行內(nèi)部應(yīng)用添加編輯操作時,引入combobox是非常方便的操作,這篇文章主要介紹了jQuery Easyui datagrid editor為combobox時指定數(shù)據(jù)源實例,有興趣的可以了解一下。 2016-12-12
-
Jquery對新插入的節(jié)點(diǎn) 綁定Click事件失效的解決方法
下面小編就為大家?guī)硪黄狫query對新插入的節(jié)點(diǎn) 綁定Click事件失效的解決方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧 2016-06-06
-
jquery中關(guān)于bind()方法的使用技巧分享
這篇文章主要給大家分享了jquery中關(guān)于bind()方法的使用技巧,文中介紹的非常詳細(xì),對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。 2017-03-03
-
淺談jquery fullpage 插件增加頭部和版權(quán)的方法
下面小編就為大家分享一篇淺談jquery fullpage 插件增加頭部和版權(quán)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看 2018-03-03
-
Raphael一個用于在網(wǎng)頁中繪制矢量圖形的Javascript庫
Raphael是一個用于在網(wǎng)頁中繪制矢量圖形的Javascript庫,它使用 SVG W3C 推薦標(biāo)準(zhǔn)和 VML 作為創(chuàng)建圖形的基礎(chǔ),你可以通過 JavaScript 操作 DOM 來輕松創(chuàng)建出各種復(fù)雜的柱狀圖、餅圖、曲線圖等各種圖表,接下來詳細(xì)介紹,感興趣的朋友可以了解下哦 2013-01-01
-
jQuery實現(xiàn)統(tǒng)計輸入文字個數(shù)的方法
這篇文章主要介紹了jQuery實現(xiàn)統(tǒng)計輸入文字個數(shù)的方法,涉及jQuery操作鼠標(biāo)事件及dom元素的技巧,具有一定參考借鑒價值,需要的朋友可以參考下 2015-03-03
最新評論
本文實例講述了jquery實現(xiàn)的美女拼圖游戲。分享給大家供大家參考。具體如下:
這里可以自由打亂拼圖次序,3*3,4*4等多種組合來進(jìn)行格數(shù)拼圖
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Jquery-puzzle by 4074</title> <style> html{ height:100%; } body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,button,textarea,p,blockquote,th,td{ padding:0; margin:0; } body{ font-family: "Helvetica Neue", "Hiragino Sans GB", "Segoe UI", "Microsoft Yahei", "微軟雅黑", Tahoma, Arial, STHeiti, sans-serif; font-size:12px; background:#fff; color:#333; } a{ outline:none; -moz-outline:none; text-decoration:none; } .clearfix{ zoom:1; _height:1px; } .clearfix:after{ content:"."; display:block; height:0; clear:both; visibility:hidden; } .head{ height:50px; line-height:50px; padding-left:20px; border-bottom:1px solid #eee; box-shadow: 1px 1px 5px #ccc; } .head h1{ float:left; width:320px; font-weight:normal; font-size:22px; } .head span{ display:block; float:right; font-size:12px; color:#999; line-height:14px; margin:30px 10px 0 0; } .wrap{ width:1000px; margin:80px auto; } .play_wrap{ width:300px; float:left; padding:20px; margin-left:200px; } #play_area{ position:relative; width:300px; height:300px; margin:auto; background:#fefefe; border-radius:2px; color: black; box-shadow: 0px 0px 8px #09F; border:1px solid #fff; *border:1px solid #e5e5e5; cursor:default; } #play_area .play_cell{ width:48px; height:48px; border:1px solid #fff; border-radius:4px; position:absolute; background-position: 5px 5px; cursor: default; z-index:80; box-shadow:0px 0px 8px #fff; transition-property:background-position; transition-duration:300ms; transition-timing-function:ease-in-out; } #play_area .play_cell.hover{ filter: alpha(opacity=80); opacity:.8; box-shadow: 0px 0px 8px #000; z-index:90; *border:1px solid #09F; } .play_menu{ float:left; margin-left:60px; font-size:14px; padding-top:20px; } .play_menu p{ line-height:200%; clear:both; } .play_menu a.play_btn{ display:block; margin-bottom:20px; width:80px; height:28px; line-height:28px; text-align:center; text-decoration:none; color:#333; background:#fefefe; border:1px solid #eee; border-radius: 2px; box-shadow: 1px 1px 2px #eee; border-color: #ddd #d2d2d2 #d2d2d2 #ddd; outline:none; -moz-outline:none; } .play_menu a.play_btn:hover{ background-color: #fcfcfc; border-color: #ccc; box-shadow: inset 0 -2px 6px #eee; } .play_menu a#play_btn_level{ position:relative; margin-bottom:30px; } .level_text{ margin-left:-10px; } .level_icon{ display:block; position:absolute; top:12px; right:16px; width:0; height:0; overflow:hidden; border:5px solid #FFF; border-color:#999 transparent transparent transparent; } .level_menu{ position:absolute; margin:-30px 0 0px 1px; display:none; } .level_menu ul{ list-style:none; } .level_menu li{ float:left; } .level_menu li a{ display:block; padding:3px 10px; border:1px solid #e8e8e8; margin-left:-1px; color:#09c; } .level_menu li a:hover{ background:#09c; color:#fefefe; } #info{ font-size:16px; margin:30px 0 0 0; } #info a{ color:#09F; } </style> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript"> var puzzleGame = function(options){ this.img = options.img || ""; this.e_playArea = $("#play_area"); this.e_startBtn = $("#play_btn_start"); this.e_playScore = $("#play_score"); this.e_playCount = $("#play_count"); this.e_levelBtn = $("#play_btn_level"); this.e_levelMenu = $("#play_menu_level"); this.areaWidth = parseInt(this.e_playArea.css("width")); this.areaHeight = parseInt(this.e_playArea.css("height")); this.offX = this.e_playArea.offset().left; this.offY = this.e_playArea.offset().top; this.levelArr = [[3,3],[4,4],[6,6]]; this.level = 1; this.scoreArr = [100,200,400]; this.score = 0; this.playCount = 0; this.cellRow = this.levelArr[this.level][0]; this.cellCol = this.levelArr[this.level][1]; this.cellWidth = this.areaWidth/this.cellCol; this.cellHeight = this.areaHeight/this.cellRow; this.imgArr = []; this.ranArr = []; this.cellArr = []; this.easing = 'swing'; this.time = 400; this.thisLeft = 0; this.thisTop = 0; this.nextIndex; this.thisIndex; this.cb_cellDown = $.Callbacks(); this.isInit = false; this.isBind = false; this.start(); }; puzzleGame.prototype = { start:function(){ this.init(); this.menu(); }, set: function(options){ this.level = options.level === 0 ? 0 : (options.level || 1); }, menu:function(){ var self = this; this.e_startBtn.click(function(){ self.e_levelMenu.hide(); self.play(); }); this.e_levelBtn.click(function(){ if(self.playing) return; self.e_levelMenu.toggle(); }); this.e_levelMenu.find("a").click(function(){ self.e_levelMenu.hide(); self.e_levelBtn.find(".level_text").html($(this).html()) if(parseInt($(this).attr("level")) !== self.level){ self.set({ "level": $(this).attr("level") }); self.isInit = true; self.isBind = false; } }) }, play:function(){ if(this.isInit){ this.isInit = false; this.cellRow = this.levelArr[this.level][0]; this.cellCol = this.levelArr[this.level][1]; this.cellWidth = this.areaWidth/this.cellCol; this.cellHeight = this.areaHeight/this.cellRow; this.init(); } this.e_playCount.html(this.playCount = 0); this.randomImg(); if(!this.isBind)this.bindCell(); }, init:function(){ var _cell; this.cellArr = []; this.imgArr = []; this.e_playArea.html(""); for(var i = 0; i<this.cellRow; i++){ for(var j = 0; j<this.cellCol; j++){ this.imgArr.push(i*this.cellCol + j); _cell = document.createElement("div"); _cell.className = "play_cell"; $(_cell).css({ "width": this.cellWidth-2, "height": this.cellHeight-2, "left": j * this.cellWidth, "top": i * this.cellHeight, "background": "url(" + this.img + ")", "backgroundPosition": (-j) * this.cellWidth + "px " + (-i) * this.cellHeight + "px" }); this.cellArr.push($(_cell)); this.e_playArea.append(_cell); } } }, randomImg:function(){ var ran,arr; arr = this.imgArr.slice(); this.ranArr = []; for(var i = 0, ilen = arr.length; i < ilen; i++){ ran = Math.floor(Math.random() * arr.length); this.ranArr.push(arr[ran]); this.cellArr[i].css({ "backgroundPosition": (-arr[ran]%this.cellCol) * this.cellWidth + "px " + (-Math.floor(arr[ran]/this.cellCol)) * this.cellHeight + "px" }) arr.splice(ran,1); } $("#p").html(this.ranArr.join()) }, bindCell:function(){ var self = this; this.isBind = true; this.cb_cellDown.add(self.cellDown); for(var i = 0, len = this.cellArr.length; i<len; i++){ this.cellArr[i].on({ "mouseover": function(){ $(this).addClass("hover"); }, "mouseout": function(){ $(this).removeClass("hover"); }, "mousedown": function(e){ self.cb_cellDown.fire(e, $(this), self); return false; } }); } }, cellDown:function(e,_cell,self){ var //self = this, _x = e.pageX - _cell.offset().left, _y = e.pageY - _cell.offset().top; self.thisLeft = _cell.css("left"); self.thisTop = _cell.css("top"); self.thisIndex = Math.floor(parseInt(self.thisTop)/self.cellHeight)*self.cellCol; self.thisIndex += Math.floor(parseInt(self.thisLeft)/self.cellWidth); _cell.css("zIndex",99); $(document).on({ "mousemove": function(e){ _cell.css({ "left": e.pageX - self.offX - _x, "top": e.pageY - self.offY - _y }) }, "mouseup": function(e){ $(document).off("mouseup"); $(document).off("mousemove"); self.cb_cellDown.empty(); if( e.pageX - self.offX < 0 || e.pageX - self.offX > self.areaWidth || e.pageY - self.offY < 0 || e.pageY - self.offY > self.areaHeight ){ self.returnCell(); return; } var _tx, _ty, _ti, _tj; _tx = e.pageX - self.offX; _ty = e.pageY - self.offY; _ti = Math.floor( _ty / self.cellHeight ); _tj = Math.floor( _tx / self.cellWidth ); self.nextIndex = _ti*self.cellCol + _tj; if(self.nextIndex == self.thisIndex){ self.returnCell(); }else{ self.changeCell(); } } }) }, changeCell:function(){ var self = this, _tc = this.cellArr[this.thisIndex], _tl = this.thisLeft, _tt = this.thisTop, _nc = this.cellArr[this.nextIndex], _nl = (this.nextIndex % this.cellCol) * this.cellWidth, _nt = Math.floor(this.nextIndex / this.cellCol) * this.cellHeight; _nc.css("zIndex",98); this.cellArr[this.nextIndex] = _tc; this.cellArr[this.thisIndex] = _nc; this.ranArr[this.nextIndex] = this.ranArr[this.nextIndex] + this.ranArr[this.thisIndex]; this.ranArr[this.thisIndex] = this.ranArr[this.nextIndex] - this.ranArr[this.thisIndex]; this.ranArr[this.nextIndex] = this.ranArr[this.nextIndex] - this.ranArr[this.thisIndex]; _tc.animate({ "left": _nl, "top": _nt },self.time,self.easing,function(){ _tc.removeClass("hover"); _tc.css("zIndex",""); }) _nc.animate({ "left": _tl, "top": _tt },self.time,self.easing,function(){ _nc.removeClass("hover"); _nc.css("zIndex",""); self.check(); if(!self.cb_cellDown.has(self.cellDown)) self.cb_cellDown.add(self.cellDown); }) }, returnCell:function(){ var self = this; this.cellArr[this.thisIndex].animate({ "left": self.thisLeft, "top": self.thisTop },self.time,self.easing,function(){ $(this).removeClass("hover"); $(this).css("zIndex",""); if(!self.cb_cellDown.has(self.cellDown)) self.cb_cellDown.add(self.cellDown); }); }, check:function(){ this.e_playCount.html( ++ this.playCount); if(this.ranArr.join() == this.imgArr.join()){ this.success(); } }, success:function(){ alert("ok"); this.score += this.scoreArr[this.level] this.e_playScore.html(this.score); } } $(document).ready(function(e) { var pg = new puzzleGame({ img: "images/120908-1347075337_M.jpg" }); }); </script> </head> <body> <div class="wrap"> <div class="play_wrap"> <div id="play_area"></div> </div> <div class="play_menu"> <a id="play_btn_start" class="play_btn" href="javascript:void(0);" unselectable="on">開始</a> <a id="play_btn_level" class="play_btn" href="javascript:void(0);" unselectable="on"> <span class="level_text">4 x 4</span> <span class="level_icon"></span> </a> <div class="level_menu" id="play_menu_level"> <ul> <li> <a href="javascript:void(0);" level=0 >3 x 3</a> </li> <li> <a href="javascript:void(0);" level=1 >4 x 4</a> </li> <li> <a href="javascript:void(0);" level=2 >6 x 6</a> </li> </ul> </div> <p>完成:<span id="play_score">0</span></p> <p>交換:<span id="play_count">0</span></p> <p>說明:<br> -點(diǎn)擊開始,小圖片將隨機(jī)打亂;<br> -拖動小圖片可交換位置,順序完全正確則為成功;<br> -難度分“3x3”、“4x4”、“6x6”三級;<br> -對應(yīng)的分值為100、200、400; </p> </div> </div> </body> </html>
希望本文所述對大家的jQuery程序設(shè)計有所幫助。
相關(guān)文章
基于jquery的二級聯(lián)動菜單實現(xiàn)代碼
基于jquery的二級聯(lián)動菜單實現(xiàn)代碼,腳本之家簡單整理了幾種。需要的朋友可以參考下,主要是思路2011-04-04jQuery Easyui datagrid editor為combobox時指定數(shù)據(jù)源實例
當(dāng)在datagrid行內(nèi)部應(yīng)用添加編輯操作時,引入combobox是非常方便的操作,這篇文章主要介紹了jQuery Easyui datagrid editor為combobox時指定數(shù)據(jù)源實例,有興趣的可以了解一下。2016-12-12Jquery對新插入的節(jié)點(diǎn) 綁定Click事件失效的解決方法
下面小編就為大家?guī)硪黄狫query對新插入的節(jié)點(diǎn) 綁定Click事件失效的解決方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06jquery中關(guān)于bind()方法的使用技巧分享
這篇文章主要給大家分享了jquery中關(guān)于bind()方法的使用技巧,文中介紹的非常詳細(xì),對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-03-03淺談jquery fullpage 插件增加頭部和版權(quán)的方法
下面小編就為大家分享一篇淺談jquery fullpage 插件增加頭部和版權(quán)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看2018-03-03Raphael一個用于在網(wǎng)頁中繪制矢量圖形的Javascript庫
Raphael是一個用于在網(wǎng)頁中繪制矢量圖形的Javascript庫,它使用 SVG W3C 推薦標(biāo)準(zhǔn)和 VML 作為創(chuàng)建圖形的基礎(chǔ),你可以通過 JavaScript 操作 DOM 來輕松創(chuàng)建出各種復(fù)雜的柱狀圖、餅圖、曲線圖等各種圖表,接下來詳細(xì)介紹,感興趣的朋友可以了解下哦2013-01-01jQuery實現(xiàn)統(tǒng)計輸入文字個數(shù)的方法
這篇文章主要介紹了jQuery實現(xiàn)統(tǒng)計輸入文字個數(shù)的方法,涉及jQuery操作鼠標(biāo)事件及dom元素的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03