HTML5Canvas Jquery实现菜单导航,利用Canvas画出了左边的3D效果,Jquery做切换时的动态效果。查看示例演示时确保您的浏览器支持Canvas元素。
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#menuMain{
float: left;
margin: 20px 0 0 100px;
}
#menuLeft {
width: 200px;
float: left;
border: 1px solid #ccc;
background-color: #efefef;
}
#menuRight{
float:left;
width: 350px;
height:335px;
float: left;
border: 1px solid #ccc;
background-color: #efefef;
}
#menuLeft>ul>li, #menuLeft>ul {
margin: 0;
padding: 0;
}
#menuLeft>ul>li {
list-style: none;
float:left;
}
#menuLeft>ul>li>a {
float: left;
height:46px;
padding-top:20px;
width: 200px;
font: 16px "微软雅黑", Arial, Helvetica, sans-serif;
border-bottom: 1px solid #ccc;
}
#menuLeft>ul>li>a:hover{
color:#ff4400;
}
#menuLeft>ul>li:nth-child(5)>a{
border-bottom: 1px solid #efefef;
}
#mark{
position:absolute;
z-index:999;
margin-left:-20px !important;
height:56px;
}
#mark>a{
height:66px;
background-color:#0064c4;
color:#fff;
float:left;
-webkit-box-shadow: -3px 0px 3px #808080;
-moz-box-shadow: 3px 0px 3px #808080;
box-shadow: 3px 0px 3px #808080;
width:100%;
}
#mCanvas{
float:left;
width:20px;
height:56px;
}
|
html
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<div id="menuMain">
<div id="menuLeft">
<ul>
<li><a>HTML</a></li>
<li><a>Javascript</a></li>
<li><a>Jquery</a></li>
<li><a>CSS</a></li>
<li><a>PHP</a></li>
<li id="mark"><canvas id="mCanvas" width="10" height="70">你的浏览器不支持HTML5Canvas,无法演示效果</canvas><a>HTML</a></li>
</ul>
</div>
<div id="menuRight"><p style="margin-top:150px;"><a>查看源代码</a></p> </div>
</div>
|
javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
var CanvasMenu={
Init:function(){
$("#mCanvas").css("height",($("#menuLeft").height()-4)/5 10 "px");
$("#menuRight").css("height",$("#menuLeft").height());
CanvasMenu.Draw();
CanvasMenu.Animate();
},
Draw:function(){
var myCanvas = document.getElementById("mCanvas");
var draw = myCanvas.getContext("2d");
draw.beginPath();
draw.fillStyle = "#0064c4";
draw.fillRect(0,0,10, 61);
draw.fill();
draw.beginPath();
draw.fillStyle = "#0064c4";
draw.globalAlpha=0.7;
draw.moveTo(0, 61);
draw.lineTo(10, 61);
draw.lineTo(10, 68);
draw.fill();
},
Animate:function(){
$("#menuLeft>ul>li>a").click(function(event){
var marginTop=$(event.target).offset().top-168;
$("#mark>a").html($(event.target).html());
var currentTop=$("#mark").offset().top-168;
if(marginTop==currentTop){
return;
}
if(marginTop>currentTop){
$("#mark").animate({marginTop:marginTop "px"},200,function(){
$("#mark").animate({marginTop:marginTop-20 "px"},100,function(){
$("#mark").animate({marginTop:marginTop "px"},100);
});
});}else{
$("#mark").animate({marginTop:marginTop "px"},200,function(){
$("#mark").animate({marginTop:marginTop 20 "px"},100,function(){
$("#mark").animate({marginTop:marginTop "px"},100);
});
});
}
});
$("#mark").click(function(event){
event.stopPropagation();
});
}
}
|