導航:首頁 > 編程語言 > js動態添加熱點

js動態添加熱點

發布時間:2024-09-10 12:18:30

Ⅰ 如何實現地圖熱點區域動態變色 js

使用背景圖片做圓角框,使用DIV+Css做圓角框代碼比較復雜。滑鼠經過變色,對於鏈接用a:hover實現;對於其他的就要用javaScript了。#header#mainNa

Ⅱ js圖片上怎麼設置熱區

//MAP1名稱
varmapName1="Map1";
//MAP1ID
varmapId1="MapId1";
//指定DIV名稱
vardivnId="mask";
//圖片路徑
varimgPath="";
main=function(type){
varobj;
switch(type){
case"aa":
//指定圖片及熱點對象取得
obj=imgMapList[0];
//創建圖片及熱點
creatImpAndHot(obj);
break;
}
}
creatImpAndHot=function(hotObj){
//創建熱點MAP對象
varmap=document.createElement_x("Map");
//設置MAP名稱
map.name=mapName1;
//設置MAPID
map.id=mapId1;
//熱點列表取得
varlength=hotObj.map.length;
for(vari=0;i<length;i++){
vartempMap=hotObj.map[i];
//創建熱區對象
area=document.createElement_x("area");
//設置熱區類型
area.shape=tempMap.shape;
//設置熱區坐標
area.coords=tempMap.coords;
//設置熱區對應鏈接
area.href=tempMap.href;
//設置熱區對應事件
area.onclick=tempMap.onclick;
//設置熱區id
area.id=tempMap.id;
//向MAP中追加熱區對象
map.appendChild(area);
}


//創建圖片對象
varimg=document.createElement_x("img");
//圖片ID
img.id=hotObj.img.id;
//設置圖片鏈接
img.src=hotObj.img.imgName;
//設置圖片對應熱區MAP
img.useMap="#"+mapName1;
//設置圖片尺寸
img.width=hotObj.img.width;
img.height=hotObj.img.height;
//邊框
img.border="0";
//設置圖片ID
img.id=hotObj.id;
//清空指定DIV內容
document.getElementByIdx_x(divnId).innerHTML='';
//向DIV區添加MAP對象
document.getElementByIdx_x(divnId).appendChild(map);
//向DIV區添加圖片對象
document.getElementByIdx_x(divnId).appendChild(img);
}
testClick=function(){
alert();
}
creatImgAndMap=function(){
vartempArray=newArray();
vartempObj=newObject();
//圖片ID
tempObj.img=newObject();
tempObj.img.id="test1";
//圖片名稱(只要圖片名稱,路徑由公共變數設置)
tempObj.img.imgName="113.jpg";
//設置圖片尺寸
tempObj.img.width="640";
tempObj.img.height="200";
vartempMap;
tempObj.map=newArray();
//熱點1
tempMap=newObject();
//熱區ID
tempMap.id="test1_hot1"
//類型
tempMap.shape="rect";
//熱區坐標
tempMap.coords="159,167,238,191";
//鏈接
tempMap.href="#";
//單擊事件
tempMap.onclick=testClick;
//添加到列表中
tempObj.map[0]=tempMap;
//熱點2
tempMap=newObject();
//熱區ID
tempMap.id="test1_hot2"
//類型
tempMap.shape="rect";
//熱區坐標
tempMap.coords="147,7,286,33";
//鏈接
tempMap.href="#";
//單擊事件
tempMap.onclick=testClick;
//添加到列表中
tempObj.map[1]=tempMap;
//將圖片及相應熱區信息添加到列表中
tempArray[0]=tempObj;
returntempArray;
};
//熱點映射
varimgMapList=creatImgAndMap();

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>無標題文檔</title>
<scripttype="text/javascript"src="img.js"></script>
<scripttype="text/javascript">
functionabc(){
main("aa");
}
</script>
</head>
<body>
<divid="mask">
<inputtype="button"value="set"onClick="abc()">
</div>
</body>
</html>

閱讀全文

與js動態添加熱點相關的資料

熱點內容
怎樣在u盤文件夾加密 瀏覽:223
applygrid 瀏覽:112
不同網路如何共享文件 瀏覽:397
紅頭文件印刷視頻 瀏覽:916
cad只能裝兩個文件 瀏覽:333
neatupload多文件 瀏覽:952
怎麼杜絕網路貸款 瀏覽:966
win8無線網路連接2 瀏覽:341
coreldraw12摳圖教程 瀏覽:733
lnmp部署後nginx配置文件位置 瀏覽:907
修改sql資料庫路徑 瀏覽:248
bibi網站有哪些好看的動漫 瀏覽:496
linux查看依賴關系 瀏覽:475
資料庫系統的組成要素 瀏覽:368
大數據文案工作一個閆多少錢 瀏覽:847
如何下載友邦app 瀏覽:19
win10系統載入的時間很慢 瀏覽:991
ug配置文件放在哪 瀏覽:235
福昕閱讀器怎麼取消雙擊關閉文件 瀏覽:227
f663n光貓超級密碼配置文件 瀏覽:610

友情鏈接