开发者

Tooltip to show above or below hotspot depending on scroll position

开发者 https://www.devze.com 2022-12-11 09:27 出处:网络
I have done some simple javascript to show and hide some div when you mouse over hot spot on a image map.

I have done some simple javascript to show and hide some div when you mouse over hot spot on a image map.

<script>
function showDiv(name) {
document.getElementById(name).style.display = "block";
}
function hideDiv(name) {
document.getElementById(name).style.display = "none";
}
</script>

The functions are appropriately called on the mouseover and mouseout e开发者_如何学Pythonvents.

At the moment the positioning is applied in the css. However I would like to extend this to show the tooltip above or below the hotspot depending on the scroll position. I mean at the moment if you mouse over a hotspot which is at the bottom of the screen, the div that appears will appear out of view, the visitor will have to scroll down to see it. I would like it to appear above the hotspot in such cases.

Any suggestions, thanks.


I once put something together using Prototype (getDimensions() / viewport.getScrollOffsets() are lifesavers!), but can't find the code any more. I just remember that figuring out what offset to use with what positioning looks easy, but takes a lot of time until it actually works.

You may want to build on an existing solution (or take a peek into one to see how they do positioning) . Nick Stakenburg's Prototip (warning not entirely free, check the license page) is very good and flexible, but there are dozens of scripts out there for all frameworks.

For framework-independent solutions check DynamicDrive, they work even though the code sometimes makes your toenails curl.

0

精彩评论

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