0

我已经为带有社交链接的图像制作了图像映射。但是,当我将链接更改为在新窗口中打开时,我失去了OnMouseOver光标。顺便说一句,这一切都在 JavaScript 中。我试图把它放进去,但它似乎在任何地方都不起作用。当我单击图像时,它们会转到一个新窗口,但光标不会改变,因此用户不知道它们在链接上。代码如下。

任何关于如何找回它的想法都会很棒。谢谢!

document.getElementById('topdiv').innerHTML = "<img border=\"0\" style=\"padding-right: 10px;\" src=\"../images/social_hor.png\" usemap=\"#socialmap\"><map name=\"socialmap\"><area shape=\"rect\" coords=\"320,0,365,50\" onClick=\"window.open('https://www.facebook.com/NCHSoftware')\" OnMouseOver='this.style.cursor='pointer';'><area shape=\"rect\" coords=\"375,0,420,50\" onClick=\"window.open('https://plus.google.com/+nchsoftware')\"><area shape=\"rect\" coords=\"425,0,470,50\" onClick=\"window.open('https://twitter.com/nchsoftware')\">"
4

1 回答 1

1

所以我已经翻译了你在你的问题中发布的那个可怕的行(我想这就是为什么人们没有考虑你的问题)并且我已经为你想出了这个例子,当然你仍然需要正确地实现它在您的页面中。

CSS

myImage {
    padding-right: 10px;
}

HTML

<div id="topdiv"></div>

Javascript

var topdiv = document.getElementById('topdiv'),
    map,
    tempVar;

function area1() {
    alert("you clicked in area1");
}

function area2() {
    alert("you clicked in area2");
}

function area3() {
    alert("you clicked in area3");
}

function pointerOn(evt) {
    evt.target.style.cursor = "hand";
}

function pointerOff(evt) {
    evt.target.style.cursor = "auto";
}

map = document.createElement("map");
map.name = "socialmap";

tempVar = document.createElement("area");
tempVar.shape = "rect";
tempVar.coords = "0,0,99,50";
tempVar.href = "#";
tempVar.addEventListener("click", area1, false);
tempVar.addEventListener("mouseover", pointerOn, false);
tempVar.addEventListener("mouseout", pointerOff, false);
map.appendChild(tempVar);

tempVar = document.createElement("area");
tempVar.shape = "rect";
tempVar.coords = "100,0,199,50";
tempVar.href = "#";
tempVar.addEventListener("click", area2, false);
tempVar.addEventListener("mouseover", pointerOn, false);
tempVar.addEventListener("mouseout", pointerOff, false);
map.appendChild(tempVar);

tempVar = document.createElement("area");
tempVar.shape = "rect";
tempVar.coords = "200,0,299,50";
tempVar.href = "#";
tempVar.addEventListener("click", area3, false);
tempVar.addEventListener("mouseover", pointerOn, false);
tempVar.addEventListener("mouseout", pointerOff, false);
map.appendChild(tempVar);

topdiv.appendChild(map);

tempVar = document.createElement("img");
tempVar.className = "myImage";
tempVar.src = "http://i860.photobucket.com/albums/ab165/ATnightshift/image001.gif";
tempVar.useMap = "#socialmap";
topdiv.appendChild(tempVar);

jsfiddle 上

于 2013-04-27T00:44:49.500 回答