admin管理员组文章数量:1435859
Is there a way for me to check if the mouse is over a visible part of a PNG image?
Each section is it's own image with a transparent background like:
So basically I want the opacity of each region to be 1 when it is hovered, and the opacity to be 0.5 when not hovering over it. Therefore the user can see which region is being hovered over.
Is there something like onmouseover if mouse position on image != transparent then...
Is there a way for me to check if the mouse is over a visible part of a PNG image?
Each section is it's own image with a transparent background like:
So basically I want the opacity of each region to be 1 when it is hovered, and the opacity to be 0.5 when not hovering over it. Therefore the user can see which region is being hovered over.
Is there something like onmouseover if mouse position on image != transparent then...
Share Improve this question edited Feb 8, 2017 at 15:06 CommunityBot 11 silver badge asked Oct 28, 2015 at 13:59 FriedpansellerFriedpanseller 7093 gold badges17 silver badges34 bronze badges 4- 4 There's no way to do this with a plain PNG - the hover event is fired on the image as a whole, not it's opaque areas. Using SVG would be best suited to what you require. You could also use an image map, but that's very outdated. – Rory McCrossan Commented Oct 28, 2015 at 14:00
- 1 Try image map! www.image-maps./ Take a look at www.galerijaziema.lv/ziema.php – Kristine Commented Oct 28, 2015 at 14:01
- Hey Rory! If i have SVG versions of the images, how would I get it to work? I can convert them all the SVG in Illustrator – Friedpanseller Commented Oct 28, 2015 at 14:32
- It might be better to ask how to do this with SVGs as a separate question (assuming it hasn't been asked before) since you already have answers here on how to do this with PNGs and that was the original question. – BSMP Commented Oct 28, 2015 at 14:46
3 Answers
Reset to default 4Have a look at http://www.w3schools./tags/tag_area.asp
You can take image and you will get cords for each poly by using some image tool like photoshop etc and you can handle each hover event for specific region in area tag for Image.
Simply its easy to use and to make clickable map.
Take specific image in two copy.one before href link and next next href link images..
<script type='text/javascript'>
$(document).ready(function()
{
$(".button").hover(function()
{
$(this).attr("src","button-hover.png");
},
function()
{
$(this).attr("src","button.png");
}
);
}
);
</script>
<body>
<img src="button.png" alt="My button" class="button" />
</body>
</html>
It is programmable in HTML5, without any tools or manually build the <map> <area shape=poly coords="325,25,262,....>
- Load your layers into many hidden canvas.
- monitor the mouse cursor relative position of the base image.
- check if the same pixel by position offset is white or not white on each canvas.
- toggle opacity accordingly
challenges
- performance
- also support touch and hover-less devices
本文标签: jqueryJavascript Hover over visible part of PNG imageStack Overflow
版权声明:本文标题:jquery - Javascript Hover over visible part of PNG image - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745666148a2669300.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论