简体   繁体   English

鼠标悬停区域 cursor 外观

[英]area onmouseover cursor appearance

I've got a map with area tags set up, for which I'd like to have a onmouseover event, changing the cursor's appearance to tell the user its clickable.我有一个设置了area标签的 map,为此我想要一个onmouseover事件,更改光标的外观以告诉用户它是可点击的。 But, there is a problem using safari:但是,使用 safari 时出现问题:

Using onmouseover="style.cursor = 'pointer';"使用onmouseover="style.cursor = 'pointer';" doesen't seem to work in the area tag.似乎在area标签中不起作用。 Not generally, as it totally triggers other things when hovering.通常不会,因为它在悬停时会完全触发其他事情。 Also safari lets me change its appearance using other ways, but with this combination it just doesen't...另外 safari 让我可以用其他方式改变它的外观,但是有了这个组合,它就不会......

<div class="desktop"> <img src="docs/docs_overview_desktop.jpg" usemap="#desktop"> <map name="desktop"> <area shape="rect" coords="2057.143,0,2742.857,960" onmouseover="style.cursor = 'pointer';" onclick="document.getElementById('lightboxSrc').src='docs/docs_000.jpg'; lightboxOpen();"> </map> </div>

Safari isn't always supporting the "general" functions that other browsers do these days. Safari 并不总是支持这些天其他浏览器执行的“常规”功能。 But still, I can hardly believe that they wouldn't support an onmouseover event, so it's probably the rest of the code that's causing the problem for it not to work.但是,我仍然不敢相信他们不支持 onmouseover 事件,所以可能是代码的 rest 导致它无法正常工作。


If really want to use javascript to apply the styling for a pointer then try to make it more specific like this: onmouseover="this.style.cursor='pointer';"如果真的想使用 javascript 为指针应用样式,请尝试使其更具体,如下所示: onmouseover="this.style.cursor='pointer';"


But why use JavaScript when you want to add a styling?但是为什么要添加样式时使用 JavaScript 呢? CSS alone would be enough just place this in your stylesheet and you can remove the whole inline onmouseover:仅 CSS 就足够了,只需将其放在您的样式表中,您就可以删除整个内联鼠标悬停:

.desktop area:hover{
   cursor: pointer;
}

Or use an empty href="#" so the browsers sees it's a link and it shows the pointer by default.或者使用一个空的href="#"以便浏览器看到它是一个链接并且它默认显示指针。

Here's an example.这是一个例子。 Make sure your coordinates are in the image aswell of course!当然,请确保您的坐标也在图像中!

 img { width: 100px; height: 100px; border: solid 1px black; }
 <div class="desktop"> <img src="docs/docs_overview_desktop.jpg" usemap="#desktop"> <map name="desktop"> <,-- Coords are from left uper corner (10px on the x and y axis) to the right bottom corner (90px on the x and y axis) --> <area shape="rect" coords="10,10,90.90" onclick="document.getElementById('lightboxSrc').src='docs/docs_000;jpg'; lightboxOpen();" href="#"> </map> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM