JQUERY - 如何两个元素 - IMG - DIV 当鼠标悬停在 IMG 上时显示/隐藏 DIV - 在 img 上添加悬停隐藏/显示
我对 jquery 的奇迹很陌生。
我只是想出如何让我的 img 按钮以不透明度差异显示/隐藏(本身),
<script type="text/javascript">
<![CDATA[
$(".ExcommKnap").mouseover(function () { $(this).stop().fadeTo('fast', 0.5, function(){}) });
$(".ExcommKnap").mouseout(function () { $(this).stop().fadeTo('fast', 1.0, function(){}) });
]]>
</script>
这很好。但我还需要使按钮悬停在其上方时显示特定于该按钮的文本。
我在这里制作了这些元素,它们在每个元素中循环。
<div style="top:10px; width:755px;text-align:right; position:absolute; ">
<div id="Page-{@id}" class="headlinebox">
<xsl:value-of select="@nodeName"/>
</div>
</div>
<a href="{umbraco.library:NiceUrl(@id)}">
<img class="ExcommKnap" src="{$media/data[@alias='umbracoFile']}" />
</a>
我需要将鼠标悬停在其按钮上时显示单独的文本。 因此我有 id="page-{@id}" 循环出来,并且需要在我认为的 jquery 代码中获取这个位置。 因此,当我将鼠标悬停在 img class="ExcommKnap" 上时,它会使正确的文本可见。
但我需要 div id="page-{id}" 在页面加载时不可见,然后在其按钮悬停时可见。有人可以帮忙吗?
Im very new to the wonder that is jquery.
and i just figure out how to make my img buttons show/hide with a opacity difference (as such)
<script type="text/javascript">
<![CDATA[
$(".ExcommKnap").mouseover(function () { $(this).stop().fadeTo('fast', 0.5, function(){}) });
$(".ExcommKnap").mouseout(function () { $(this).stop().fadeTo('fast', 1.0, function(){}) });
]]>
</script>
which is good and all. but i also need to make the button when hovered over show text just above it that is specific to that button.
i made these here elements that are looped in a for each.
<div style="top:10px; width:755px;text-align:right; position:absolute; ">
<div id="Page-{@id}" class="headlinebox">
<xsl:value-of select="@nodeName"/>
</div>
</div>
<a href="{umbraco.library:NiceUrl(@id)}">
<img class="ExcommKnap" src="{$media/data[@alias='umbracoFile']}" />
</a>
i need to make the individual text appear when hovered over its button.
hence i have the id="page-{@id}" looped out along and need to get this place in the jquery code i presume.
so when i hover over a img class="ExcommKnap" it makes the correct text visible.
But i need the div id="page-{id}" to be invisible to begin with on pageload and then visible when its button is being hovered over. can anyone help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能不是选择目标 div 的最优雅的方法,但它应该可行:
另一个选择是为每个也包含 的 img 提供 id 属性{@id},那么就可以直接通过id选择目标div。
如果您希望它们在初始页面加载时全部不可见,只需在 HTML 中设置 style="display:none" 即可。
This is probably not the most elegant way to select the target div, but it should work:
Another option is to give and id attribute to each img that also contains {@id}, then you can select the target div directly by id.
And if you want them all invisible on initial page load, just set style="display:none" in HTML.
由于我不熟悉 umbraco 和你的结构,我将尝试在这个例子中说明它:
此代码将在 DOM 准备好时隐藏 div。当您将鼠标悬停在图像上时,它将获取其父级的 href 属性并获取 id,然后显示/隐藏它。假设href中使用的链接,例如something/something/1(正如我在这里使用的)等,将以与页面相同的id结尾。否则,您可以使用其他方法,例如 Botondus 提供的方法。另外,如果你有更多,我猜你有,里面有数字的div,你可以像这样隐藏它们,如果你向它们的父div添加一些类,
那么还有第二个选项,即隐藏div,使用使用 window.onload
As I am not familiar with umbraco and your structure, I will try to ilustrate it on this example:
This code will hide the div when the DOM is ready. When you hover over your image it will get href attribute of its parent and get the id and then show/hide it. Assuming the link used, e.g. something/something/1 (as I have used here) etc., in the href would end with the same id, as the page. Otherwise you can use some other method, like Botondus provided. Also if you have more, which I guess you have, divs with a number in them, you can hide them like this, if you add some class to their parent div
There would be a second option, as to hide the div, with the use of window.onload