简体   繁体   English

浮动文字叠加在图片悬停上

[英]Floating text overlay on image hover

What I'm trying to do: When a user hovers over any image on a specific page, a floating box element appears, displaying the Image's title (the html title="" tag). 我正在尝试做的是:当用户将鼠标悬停在特定页面上的任何图像上时,会出现一个浮动框元素,显示图像的标题(html title =“”标签)。 As the user moves their cursor across the image, the box element moves along with it. 当用户在图像上移动光标时,框元素也会随之移动。

(Example: http://minecraft.gamepedia.com/Glass_Bottle - If you looking under the "crafting" section, hovering over certain images displays a box with it's title - Sorry, this was the only example that I could find). (示例: http : //minecraft-zh.gamepedia.com/Glass_Bottle-如果您在“工艺”部分下查看,将鼠标悬停在某些图像上会显示一个带有标题的框-对不起,这是我唯一能找到的示例)。

Is it possible to achieve this result utilising raw HTML, or does this require css or an addition such as Javascript/Jquery? 是否可以使用原始HTML来实现此结果,还是需要CSS或Javascript / Jquery之类的附加功能?

Sorry if I haven't been clear enough - if you require certain information, please let me know! 抱歉,如果我不太清楚-如果您需要某些信息,请告诉我!

Thanks in advance, and I hope everyone has a Happy New Year! 在此先感谢您,祝大家新年快乐! :) :)

I have used this a few months ago and helped me a lot with the very same problem: 几个月前,我已经使用了这个工具,并且对相同的问题也提供了很多帮助:

http://notlaura.com/show-title-hovering-image/ http://notlaura.com/show-title-hovering-image/

Hope it helps you as well, 希望它也对您有帮助,

Andrew 安德鲁

I think you need javascript. 我认为您需要JavaScript。 I don't think your going to get everything you want in HTML5. 我认为您不会在HTML5中获得所需的一切。 You want to use the mouseover event to show the image next to the cursor which means you'll have to float a div next to it. 您想使用mouseover事件在光标旁边显示图像,这意味着您必须在其旁边浮动一个div。 The moving part won't be a problem because you'll probably just reshow it for every mouse over which will get fired every time they move the cursor I think. 活动部分不会有问题,因为您可能只需要为每只鼠标重新显示它,每当鼠标移动我认为会触发的鼠标。 Here are the problems you must solve. 这是您必须解决的问题。 Figure out one at a time. 一次找出一个。

1) How to float a div at a higher z index with the title in it.
2) How to know the coordinates of your curser
3) Move the div to your cursor coordinates with an offset
4) How to hide the div

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

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