gpt4 book ai didi

javascript - 将鼠标悬停在文本上以显示图像

转载 作者:行者123 更新时间:2023-11-30 16:24:25 25 4
gpt4 key购买 nike

我的代码适用于 1 个文本,当您将鼠标悬停在它上面时会显示图像。

但我需要它来处理显示不同图像(在同一区域)的多个文本。像这样:https://handleidingen.vodafone.nl/web/samsung-galaxy-s5/basisfuncties/voicemail/oproepen-doorschakelen-naar-voicemail

这是我的代码:

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(function() {
$("#Clicker").hover(function(){
$( "#wallpaperamIMage" ).toggle();
});
});</script>
<b id="Clicker" style="color:blue;text-decoration:underline;cursor:pointer;">Altijd doorschakelen</b>
<div><img id="wallpaperamIMage" style="display:none;" src="http://cdn.mobilesupportware.com/ml/3494895.png"></div>

我该怎么做?

谢谢。

最佳答案

这应该可以正常工作:

$(function() {
$(".Clicker").hover(function(){
$( "#wallpaperamIMage" ).attr("src", $(this).data("img"))
$( "#wallpaperamIMage" ).toggle();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<b class="Clicker" style="color:blue;text-decoration:underline;cursor:pointer;" data-img="//placehold.it/200x200">Altijd doorschakelen</b>
<b class="Clicker" style="color:blue;text-decoration:underline;cursor:pointer;" data-img="//placehold.it/300x300">Altijd doorschakelen</b>
<div><img id="wallpaperamIMage" style="display:none;" src=""></div>

首先,您必须将“Clicker”更改为一个类,因为您将有多个类。

然后你可以给 <b> 添加一个数据属性带有图像源的元素。因为每个元素都有自己的图像。

然后在 Hover 事件上,您可以访问此属性并将其加载到 img 元素中。

关于javascript - 将鼠标悬停在文本上以显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34330274/

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