首页 > Web开发 > 详细

项目--HTML Canvas 和 jQuery遍历

时间:2014-05-31 08:06:27      阅读:476      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
function ReShowSelected(){
$("#Map area").each(function(){
//定义画笔属性
var canvers = document.getElementById("diagonal");
var context = canvers.getContext("2d");
context.storkeStyle = "#ccc",
context.lineWidth = 1;
context.beginPath();
//标识符
var vdata = $(this).attr("data_ID");
var flag = $(this).attr("alt");
//根据不同的标识符进行处理
//圆形
if(vdata == "R"){
if(flag == "yellow"){
var strs = new Array();
strs = $(this).attr("coords").split(",");

context.arc(strs[0], strs[1], strs[2],0, Math.PI * 2, true);

context.fillStyle = #ffff00;
$(this).attr("alt","yellow"); 
}
}
//线条
else if(vdata == "S"){
if(flag == "yellow"){
var strs = new Array();
strs = $(this).attr("coords").split(",");

var i1, i2;
for (var i = 0; i < strs.length; i++) {
if (i % 2 == 0) {
i1 = strs[i];
}
if (i % 2 == 1) {
i2 = strs[i];
if (i == 1) {
context.moveTo(i1, i2);
}
else {
context.lineTo(i1, i2);
}
}
} 

context.fillStyle = #ffff00;
$(this).attr("alt","yellow"); 
}
}
//不规则
else{
if(flag == "blue"){
var strs = new Array();
strs = $(this).attr("coords").split(",");

var i1, i2;
for (var i = 0; i < strs.length; i++) {
if (i % 2 == 0) {
i1 = strs[i];
}
if (i % 2 == 1) {
i2 = strs[i];
if (i == 1) {
context.moveTo(i1, i2);
}
else {
context.lineTo(i1, i2);
}
}
} 

context.fillStyle = #97ffff;
$(this).attr("alt","blue"); 
}
}

//填充颜色
context.fill();
context.closePath(); //闭合

});
}
bubuko.com,布布扣

 

项目--HTML Canvas 和 jQuery遍历,布布扣,bubuko.com

项目--HTML Canvas 和 jQuery遍历

原文:http://www.cnblogs.com/buzi521/p/3761379.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!