以下是 JS动态图例代码 的示例演示效果:
部分效果截图1:
部分效果截图2:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="JS代码,JS广告代码,JS特效代码" />
<meta name="description" content="此代码内容为JS动态图例代码,属于站长常用代码" />
<title> JS动态图例代码</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<!--<link href="http://fonts.googleapis.com/css?family=Cabin+Sketch:bold" rel="stylesheet" type="text/css" />-->
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/raphael.js" type="text/javascript"></script>
<script src="js/init.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<div class="legend">
<h1>Legend:</h1>
<div class="skills">
<ul>
<li class="jq">JavaScript</li>
<li class="css">CSS3</li>
<li class="html">HTML5</li>
<li class="php">PHP</li>
<li class="sql">MySQL</li>
</ul>
</div>
</div>
<div id="diagram"></div>
</div>
<div class="get">
<div class="arc">
<span class="text">JavaScript</span>
<input type="hidden" class="percent" value="95" />
<input type="hidden" class="color" value="#97BE0D" />
</div>
<div class="arc">
<span class="text">CSS3</span>
<input type="hidden" class="percent" value="90" />
<input type="hidden" class="color" value="#D84F5F" />
</div>
<div class="arc">
<span class="text">HTML5</span>
<input type="hidden" class="percent" value="80" />
<input type="hidden" class="color" value="#88B8E6" />
</div>
<div class="arc">
<span class="text">PHP</span>
<input type="hidden" class="percent" value="53" />
<input type="hidden" class="color" value="#BEDBE9" />
</div>
<div class="arc">
<span class="text">MySQL</span>
<input type="hidden" class="percent" value="45" />
<input type="hidden" class="color" value="#EDEBEE" />
</div>
</div>
</body>
</html>
JS代码(init.js):
var o ={
init:function(){
this.diagram();
}
,random:function(l,u){
return Math.floor((Math.random()*(u-l+1))+l);
}
,diagram:function(){
var r = Raphael('diagram',600,600),rad = 73,defaultText = 'Skills',speed = 250;
r.circle(300,300,85).attr({
stroke:'none',fill:'#193340'}
);
var title = r.text(300,300,defaultText).attr({
font:'20px Arial',fill:'#fff'}
).toFront();
r.customAttributes.arc = function(value,color,rad){
var v = 3.6*value,alpha = v == 360 ? 359.99:v,random = o.random(91,240),a = (random-alpha) * Math.PI/180,b = random * Math.PI/180,sx = 300 + rad * Math.cos(b),sy = 300 - rad * Math.sin(b),x = 300 + rad * Math.cos(a),y = 300 - rad * Math.sin(a),path = [['M',sx,sy],['A',rad,rad,0,+(alpha > 180),1,x,y]];
return{
path:path,stroke:color}
}
$('.get').find('.arc').each(function(i){
var t = $(this),color = t.find('.color').val(),value = t.find('.percent').val(),text = t.find('.text').text();
rad += 30;
var z = r.path().attr({
arc:[value,color,rad],'stroke-width':26}
);
z.mouseover(function(){
this.animate({
'stroke-width':50,opacity:.75}
,1000,'elastic');
if(Raphael.type != 'VML') //solves IE problemthis.toFront();
title.stop().animate({
opacity:0}
,speed,'>',function(){
this.attr({
text:text + '\n' + value + '%'}
).animate({
opacity:1}
,speed,'<');
}
);
}
).mouseout(function(){
this.stop().animate({
'stroke-width':26,opacity:1}
,speed*4,'elastic');
title.stop().animate({
opacity:0}
,speed,'>',function(){
title.attr({
text:defaultText}
).animate({
opacity:1}
,speed,'<');
}
);
}
);
}
);
}
}
$(function(){
o.init();
}
);
CSS代码(default.css):
@import url("reset.css");/* ------ layout-----------------------------------------------*/
html,body{margin:0;padding:0;}
body{background:#f5f5f5;font-family:Arial,Helvetica,sans-serif;font-size:12px;color:#333;line-height:18px;}
#content{position:absolute;top:50%;left:50%;margin:-460px 0 0 -450px;width:900px;height:600px;}
.legend{float:left;width:250px;margin-top:140px;}
#content h1{font-family:'Cabin Sketch',arial,serif;text-shadow:3px 3px 0 #ddd;color:#193340;font-size:40px;margin-bottom:40px;text-align:right;}
.skills{float:left;clear:both;width:100%;}
.skills ul,.skills li{display:block;list-style:none;margin:0;padding:0;}
.skills li{float:right;clear:both;padding:0 15px;height:35px;line-height:35px;color:#fff;margin-bottom:1px;font-size:18px;}
.skills .jq{background:#97BE0D;}
.skills .css{background:#D84F5F;}
.skills .html{background:#88B8E6;}
.skills .php{background:#BEDBE9;}
.skills .sql{background:#EDEBEE;}
.footer{position:fixed;bottom:0;left:0;width:100%;background:#2D2D2D;color:#EAEAEA;padding:20px 0;text-align:center}
.footer a{color:#EAEAEA;}
.footer a:hover{color:#E4842C;}
.footer .inside{font-family:'Cabin Sketch',arial,serif;font-size:22px;text-align:center;}
#diagram{float:right;width:600px;height:600px;}
.get{display:none;}
/* ------ anchors-----------------------------------------------*/
a{text-decoration:none;color:#333;}
CSS代码(reset.css):
/* General---------------------------------------- */
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;}
p,blockquote,q,pre,address,hr,code,samp,dl,ol,ul,form,table,fieldset,menu{margin-bottom:1.5em;}
/* Structure---------------------------------------- */
html{font-size:100%;}
/*body{font-family:arial,helvetica,sans-serif;font-size:.875em;}
*/
/* Text---------------------------------------- */
h1,h2,h3,h4,h5,h6{font-weight:bold;}
h1{font-size:3em;line-height:1.1;margin-bottom:.238em;}
h2{font-size:2em;line-height:1.15;margin-bottom:.357em;}
h3{font-size:1.5em;line-height:1.2;margin-bottom:.476em;}
h4,h5,h6{margin-bottom:.571em;}
h4{font-size:1.25em;line-height:1.25;}
h5{font-size:1em;}
h6{font-size:1em;}
em,i{font-style:italic;}
strong,b{font-weight:bold;}
blockquote,q,cite{font-style:italic;}
blockquote,q{quotes:none;}
blockquote:before,blockquote:after,q:before,q:after{content:"";content:none;}
code,kbd,pre,samp,tt{font-family:"andale mono",consolas,monaco,"lucida console","courier new",courier,monospace;line-height:1.3;}
pre{/* word-wrap:break-word;*/
white-space:pre-wrap;}
abbr,acronym,dfn{border-bottom:1px dotted;cursor:help;font-variant:normal;font-style:normal;}
var{font-style:normal;}
center{text-align:center;}
/* Hypertext---------------------------------------- */
/*a:link{}
a:visited{}
a:hover{}
a:active{}
a:focus{outline:1px dotted;}
*/
/* Image---------------------------------------- */
img{border:0;}
/* List---------------------------------------- */
ul{list-style:disc outside none;}
ol{list-style:decimal outside none;}
li{margin-left:2em;}
li ul,li ol{margin-bottom:0;}
dt{font-weight:bold;}
dd{margin-bottom:1em;}
/* Presentation---------------------------------------- */
hr{border:0;border-bottom:1px solid;}
big{font-size:1.25em;}
small,sub,sup{font-size:.85em;}
sub,sup{line-height:1;}
sub{vertical-align:bottom;}
sup{vertical-align:top;}
del,s,strike{text-decoration:line-through;}
ins{text-decoration:none;border-bottom:1px dotted;}
bdo{border-bottom:1px dotted;}
u{text-decoration:underline;}
/* Form---------------------------------------- */
fieldset{padding:1em;}
legend{font-weight:bold;padding:0 .25em;}
input,textarea,select,button{font-family:inherit;font-size:1em;}
input[type=button],input[type=file],input[type=image],input[type=reset],input[type=submit],button[type=button],button[type=reset],button[type=submit]{cursor:pointer;line-height:1;}
/*input[type=text],input[type=password],textarea{padding:1px;}
*/
textarea{text-align:left;line-height:1.25;}
/* Table---------------------------------------- */
table{border-collapse:collapse;border-spacing:0;border:0;line-height:1.3;}
caption,th,td{text-align:left;vertical-align:top;}
th,td{padding:.5em 1em;border:1px solid;}
caption{padding-bottom:1em;}
th{font-weight:bold;}
/* Classes---------------------------------------- */
ul.nolist,ul.nolist li{display:block;list-style:none;padding:0;margin:0;}
.clear{clear:both;}