gpt4 book ai didi

javascript - 当鼠标移动到带有jquery的文本上时显示图片?

转载 作者:行者123 更新时间:2023-11-28 02:54:39 26 4
gpt4 key购买 nike

您知道当鼠标移动到 html 文本上时显示图片的教程或脚本吗?

最佳答案

使用 jQuery 的基本示例如下所示:

CSS

#myImage {
display:none;
}​

HTML

<span class='pictureTrigger'>some text</span>

<img id='myImage' src='/path/to/image' />​

jQuery

$(function() {  // Makes sure DOM loads before code is run

$('.pictureTrigger').hover( // Assign event handlers for mouseenter/mouseleave

function() { $('#myImage').show(); }, // Find myImage and show it on mouseenter
function() { $('#myImage').hide(); } // Find myImage and hide it on mouseleave
);

});

如果问题没有更多细节,很难给出更好的答案。

基本思想是文本包含在 span 中,其中有一个名为 pictureTrigger 的类。不过,可以命名为任何名称。

悬停事件(实际上是两个事件的简写,mouseentermouseleave)被添加到具有 pictureTrigger 类的所有元素中。

这两个函数分别代表mouseentermouseleave事件。事件处理函数查找 ID 为 myImageimg,并显示/隐藏它。

<小时/>

相关 jQuery 文档:

关于javascript - 当鼠标移动到带有jquery的文本上时显示图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2984626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com