开发者

non-rectangular hoverable area

I would like to have an arrow which will do something on :hover but only when the arrow itself is hovered (not the rectangle which delimits its wid开发者_运维百科th and height).

In short, when you hover on the right-bottom and right-top corners of an ► it shouldn't do anything.

How would I achieve that?


With a HTML map element? See < map >.

Update:

For example, like in this demo:

img {
  border: 3px solid black;
}
<br />
<img id="img" src="http://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Black_triangle.svg/200px-Black_triangle.svg.png" usemap="#triangle" alt="" />
<map name="triangle">
    <area shape="poly" coords="3, 3, 195, 3, 100, 169"
        href="http://google.com" alt=""
        onmouseover="document.getElementById('img').style.borderColor = 'red';"
        onmouseout="document.getElementById('img').style.borderColor = 'black';"/>
</map>


Iff you have time -- learn SVG in JavaScript -- then, things like these will be nothing more than child's play.

Some useful links for SVG...

http://www.w3.org/Graphics/SVG/

this tutorial

http://raphaeljs.com/ (my favourite)

http://keith-wood.name/svg.html


You can either use oldschool imagemaps or track mousemovement throught the mousemove event and then do x/y coordinate calculations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜