小Lemon教学 *HTML代码写魔方网页* 玩玩更开心

内容:

魔方
***样式*** @CHARSET "UTF-8"; *{padding:0;margin:0;}

html{
background: -webkit-radial-gradient(center,farthest-corner,red,black);
height:100%;

}
#box{
position:absolute;
top:50%;
left:50%;
width:300px;
height:300px;
margin-top:-150px;
margin-left:-150px;
-webkit-transform-style:preserve-3d;
-webkit-perspective:800px;
}
#cube{
width:100px;
height:100px;
margin:100px auto;
-webkit-transform-style:preserve-3d;
-webkit-transition:0.5s ease all;
-webkit-transform:rotateX(-30deg) rotateY(-30deg);
}
#cube li{
display:block;
position:absolute;
width:98px;
height:98px;
border:1px solid black;
-webkit-transform-style:preserve-3d;
-webkit-transition:0.5s ease all;
-webkit-user-select:none;
z-index:10;
}
#front,#back,#left,#right,#top,#bottom{
-webkit-transform-style:preserve-3d;
-webkit-transition:0.5s ease all;
}
js
$(document).ready(function(){
var surface=new Array();
var facediv="";
var mx; //x方向位移
var my; //y方向位移
var rox=-30;
var roy=-30;
var sfid; //鼠标点击魔方的位置
/**
* 初始化魔方六个面,包括颜色,位置
*/
for(var i=1;i<=6;i++){
surface[i]=new Array();
for(var j=1;j<=9;j++){
surface[i][j]=new Array();
for(var k=1;k<=2;k++){
surface[i][j][k]="";
}
}
}

for(var i=1;i<=6;i++){
	for(var j=1;j<=9;j++){
		switch(i){
		case 1:
			surface[i][j][1]="blue";
			break;
		case 2:
			surface[i][j][1]="lime";
			break;
		case 3:
			surface[i][j][1]="red";
			break;
		case 4:
			surface[i][j][1]="yellow";
			break;
		case 5:
			surface[i][j][1]="white";
			break;
		case 6:
			surface[i][j][1]="#FFB416";
			break;
		
		}
	}
}
/**
 * 每个大面的位置
 */
local();
function local(){
for(var i=1;i<=6;i++){
	for(var j=1;j<=9;j++){
		switch(i){
		case 1:
			surface[i][j][2]="rotateY(0deg)";
			break;
		case 2:
			surface[i][j][2]="rotateY(180deg)";
			break;
		case 3:
			surface[i][j][2]="rotateY(-90deg)";
			break;
		case 4:
			surface[i][j][2]="rotateY(90deg)";
			break;
		case 5:
			surface[i][j][2]="rotateX(90deg)";
			break;
		case 6:
			surface[i][j][2]="rotateX(-90deg)";
			break;
		
		}
	}
}
/**
 * 每个面子方块的位置
 */
for(var i=1;i<=6;i++){
	surface[i][1][2] +="translateX(-100px) translateY(-100px)";
	surface[i][2][2] +="translateX(0px) translateY(-100px)";
	surface[i][3][2] +="translateX(100px) translateY(-100px)";
	surface[i][4][2] +="translateX(-100px) translateY(0px)";
	surface[i][5][2] +="translateX(0px) translateY(0px)";
	surface[i][6][2] +="translateX(100px) translateY(0px)";
	surface[i][7][2] +="translateX(-100px) translateY(100px)";
	surface[i][8][2] +="translateX(0px) translateY(100px)";
	surface[i][9][2] +="translateX(100px) translateY(100px)";
	
}}
/**
 * 一个div就是一个面,一个li就是一个格子
 */
htmldiv();
function htmldiv(){
	facediv="";
for(var i=1;i<=6;i++){
	for(var j=1;j<=9;j++){
		if(j==1){
		switch(i){
		case 1:facediv +='
'; break; case 2:facediv +='
'; break; case 3:facediv +='
'; break; case 4:facediv +='

//
var col=surface[4][j][1];
surface[4][j][1]=surface[6][10-k][1];
surface[6][10-k][1]=surface[3][10-j][1];
surface[3][10-j][1]=surface[5][k][1];
surface[5][k][1]=col;
//

		}
		
	}
	else{
		if(sfi==4||sfi==3){
		$("#back").css("-webkit-transform","rotateZ(90deg) translateX(50px) translateY(-50px)");
		topcolor1(2);
		}
		
		
		for(var j=sfj;j<=9;j+=3){
			var k=j/3;
			$("#sf5-"+k).css("-webkit-transform",surface[5][k][2].replace("deg)","deg) rotateY(90deg)")+" translateZ(150px)");
			$("#sf6-"+(10-k)).css("-webkit-transform",surface[6][10-k][2].replace("deg)","deg) rotateY(-90deg)") +" translateZ(150px)");
			$("#sf4-"+j).css("-webkit-transform",surface[4][j][2].replace("deg)","deg) rotateX(-90deg)")+" translateZ(150px)");
			$("#sf3-"+(10-j)).css("-webkit-transform",surface[3][10-j][2].replace("deg)","deg) rotateX(90deg)")+" translateZ(150px)");		
				
			var col=surface[4][j][1];
			surface[4][j][1]=surface[5][k][1];
			surface[5][k][1]=surface[3][(10-j)][1];
			surface[3][10-j][1]=surface[6][(10-k)][1];
			surface[6][(10-k)][1]=col;
		
		}
	}
	
	var time =setTimeout(function(){local()},500);

	var time1 =setTimeout(function(){htmldiv()},500);
	
}

function changlocalY2(sfj,sfi){
	if(my<0){
	
		if(sfi==4||sfi==3){
			$("#front").css("-webkit-transform","rotateZ(-90deg) translateX(-50px) translateY(-50px)");
			topcolor1(1);
		}
		for(var j=sfj;j<=3;j++){
			var k =j*3;
			
			$("#sf5-"+(10-j)).css("-webkit-transform",surface[5][10-j][2].replace("deg)","deg) rotateY(-90deg)")+" translateZ(150px)");
			$("#sf6-"+j).css("-webkit-transform",surface[6][j][2].replace("deg)","deg) rotateY(90deg)") +" translateZ(150px)");
			$("#sf4-"+(10-k)).css("-webkit-transform",surface[4][10-k][2].replace("deg)","deg) rotateX(90deg)")+" translateZ(150px)");
			$("#sf3-"+k).css("-webkit-transform",surface[3][k][2].replace("deg)","deg) rotateX(-90deg)")+" translateZ(150px)");		

//
var col=surface[4][10-k][1];
surface[4][10-k][1]=surface[6][j][1];
surface[6][j][1]=surface[3][k][1];
surface[3][k][1]=surface[5][10-j][1];
surface[5][10-j][1]=col;
//

		}
		
	}
	else{
		
		if(sfi==4||sfi==3){
			$("#front").css("-webkit-transform","rotateZ(90deg) translateX(50px) translateY(-50px)");
			topcolor2(1);
		}
		
		for(var j=sfj;j<=3;j++){
			var k=j*3;
			$("#sf5-"+(10-j)).css("-webkit-transform",surface[5][10-j][2].replace("deg)","deg) rotateY(90deg)")+" translateZ(150px)");
			$("#sf6-"+j).css("-webkit-transform",surface[6][j][2].replace("deg)","deg) rotateY(-90deg)") +" translateZ(150px)");
			$("#sf4-"+(10-k)).css("-webkit-transform",surface[4][10-k][2].replace("deg)","deg) rotateX(-90deg)")+" translateZ(150px)");
			$("#sf3-"+k).css("-webkit-transform",surface[3][k][2].replace("deg)","deg) rotateX(90deg)")+" translateZ(150px)");			
				
			var col=surface[4][10-k][1];
			surface[4][10-k][1]=surface[5][10-j][1];
			surface[5][10-j][1]=surface[3][k][1];
			surface[3][k][1]=surface[6][j][1];
			surface[6][j][1]=col;
		
		}
	}
	
	var time =setTimeout(function(){local()},500);

	var time1 =setTimeout(function(){htmldiv()},500);		
}
function changlocalY3(sfj,sfi){
	if(my<0){
		var k =2*sfj;
		for(var j=sfj;j<=9;j+=3){
			
			$("#sf5-"+k).css("-webkit-transform",surface[5][k][2].replace("deg)","deg) rotateY(-90deg)")+" translateZ(150px)");
			$("#sf6-"+(10-k)).css("-webkit-transform",surface[6][10-k][2].replace("deg)","deg) rotateY(90deg)") +" translateZ(150px)");
			$("#sf4-"+j).css("-webkit-transform",surface[4][j][2].replace("deg)","deg) rotateX(90deg)")+" translateZ(150px)");
			$("#sf3-"+(10-j)).css("-webkit-transform",surface[3][10-j][2].replace("deg)","deg) rotateX(-90deg)")+" translateZ(150px)");		
			
		var col=surface[4][j][1];
		surface[4][j][1]=surface[6][10-k][1];
		surface[6][10-k][1]=surface[3][10-j][1];
		surface[3][10-j][1]=surface[5][k][1];
		surface[5][k][1]=col;
	
		k++;
		
		}
		
	}
	else{
		var k=sfj*2;
		for(var j=sfj;j<=9;j+=3){
			
			$("#sf5-"+k).css("-webkit-transform",surface[5][k][2].replace("deg)","deg) rotateY(90deg)")+" translateZ(150px)");
			$("#sf6-"+(10-k)).css("-webkit-transform",surface[6][10-k][2].replace("deg)","deg) rotateY(-90deg)") +" translateZ(150px)");
			$("#sf4-"+j).css("-webkit-transform",surface[4][j][2].replace("deg)","deg) rotateX(-90deg)")+" translateZ(150px)");
			$("#sf3-"+(10-j)).css("-webkit-transform",surface[3][10-j][2].replace("deg)","deg) rotateX(90deg)")+" translateZ(150px)");				
				
			var col=surface[4][j][1];
			surface[4][j][1]=surface[5][k][1];
			surface[5][k][1]=surface[3][10-j][1];
			surface[3][10-j][1]=surface[6][10-k][1];
			surface[6][10-k][1]=col;
		k++;
		}
	}
	
	var time =setTimeout(function(){local()},500);

	var time1 =setTimeout(function(){htmldiv()},500);		
}

});

你可能感兴趣的:(快捷键,基础类,图形化,html5)