導航:首頁 > 編程語言 > 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動態添加熱點相關的資料

熱點內容
cad文件大很卡如何解決 瀏覽:633
將java程序打包成apk 瀏覽:277
2021唱吧文件找不到了 瀏覽:463
華為p9手機文件管理 瀏覽:284
固定在工具欄的文件夾怎麼查找路徑 瀏覽:667
半條命2有幾個版本 瀏覽:333
電腦管家微信備份文件夾 瀏覽:826
ubuntu文件夾解鎖 瀏覽:34
網站多少錢一單 瀏覽:382
系統鏡像恢復找不到文件 瀏覽:255
進什麼網站 瀏覽:588
修改了配置文件代碼沒有讀出來 瀏覽:749
vss資料庫是什麼 瀏覽:899
奇跡13單機系統找不到指定文件 瀏覽:719
flyme魅藍3以前的版本 瀏覽:318
安卓文件管理哪些文件夾可以刪除 瀏覽:290
安卓車載導航沒有聲音是怎麼回事 瀏覽:810
cjson數組格式 瀏覽:159
vb文件在哪裡 瀏覽:215
工廠里都招什麼編程人員 瀏覽:932

友情鏈接