[英]how to show inner on mouse hover of outer div with jquery
i just want to show inner div on mouse hover of outer div. 我只想在外部div的鼠标悬停上显示内部div。 here is my jquery for show div on mouse hover: 这是我关于鼠标悬停时显示div的jquery:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$('.thumb').hover(function(){
$('.option').show();
});
});
</script>
and here is my design code: 这是我的设计代码:
<asp:Repeater ID="rpt_file_list" runat="server"
onitemcommand="rpt_file_list_ItemCommand"
onitemdatabound="rpt_file_list_ItemDataBound">
<ItemTemplate>
<div class="thumb" align="center">
<table>
<tr>
<td align="center"><asp:Image ID="img1" runat="server" BorderWidth="0px"
ImageUrl="../images/Nofile_Icon1.gif" />
<br/>
<asp:Label ID="lbl_file_length" runat="server" CssClass="normaltext"
Text='<%#"("+ Eval("File_Size")+ " KB )"%>'></asp:Label>
<br/>
<asp:LinkButton ID="lbut_download" runat="server"
CommandArgument='<%# Eval("File_name")+""+Eval("File_ext")%>' CommandName="Download"
Text='<%#Eval("File_Title").ToString().Length > 15 ? Eval("File_Title").ToString().Substring(0, 15) + "..." : Eval("File_Title")%>'
ToolTip='<%#Bind("File_Title")%>'></asp:LinkButton></td>
<td valign="top"><div class="option" align="right" style="display:none">
<table>
<tr><td><asp:ImageButton ID="imbtn_download" runat="server" CommandName="Download" ImageUrl="../images/download.gif" ToolTip="Download"/></td></tr>
<tr><td><asp:ImageButton ID="ImageButton5" runat="server" CommandName="Preview" ImageUrl="../images/view.gif" ToolTip="Preview"/></td></tr>
</table>
</div></td>
</tr>
</table>
</div>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblErrorMsg" runat="server" Text="No files found." Visible="false" ForeColor="Red">
</asp:Label>
</FooterTemplate>
</asp:Repeater>
how ever it's not work properly please help me... 怎么无法正常工作,请帮助我...
You need to find the descendant element of the hovered thumb
, also you need to use toggle() so that it will get hidden when mouse leaves 您需要找到悬停的thumb
的后代元素,也需要使用toggle(),以便在鼠标离开时将其隐藏
$(document).ready(function () {
$('.thumb').hover(function () {
$(this).find('.option').toggle();
});
});
are you looking for this 你在找这个吗
$(document).ready(function () {
$('.thumb').mouseover(function () {
$('.option').show();
});
$('.thumb').mouseout(function () {
$('.option').hide();
});
});
You just need to find the options 您只需要找到选项
$(document).ready(function(){
$('.thumb').hover(function(){
$(this).find('.option').toggle(); //this will take care of show hide
});
});
$(document).ready(function(){
$(".thumb").hover(function(){
$(".option").toggle();
});
});
fiddler http://jsfiddle.net/6a6Fx/1/ 提琴手http://jsfiddle.net/6a6Fx/1/
hover() take two handler which are fired when your mouse enter the div and when your mouse leave the div. hover()带有两个处理程序,当您的鼠标进入div和当您的鼠标离开div时将被触发。 Also, you can use $(this)
to target current hover .thumb
div and find()
to find the child with class option
under your current hovered .thumb
: 另外,您可以使用$(this)
来定位当前悬停.thumb
div并使用find()
在当前悬停的.thumb
下查找带有class option
的孩子:
$(document).ready(function () {
$(".thumb").hover(function() {
$(this).find('.option').show();
}, function() {
$(this).find('.option').hide();
});
});
or you can use toggle()
to toggle between show and hide instead of two separate function: 或者您可以使用toggle()
在显示和隐藏之间切换,而不是使用两个单独的函数:
$(document).ready(function () {
$('.thumb').hover(function () {
$(this).find('.option').toggle();
});
});
I think you are trying to show and hide a child element if you mouse over an element, you can try this code which will work perfectly for your scenario. 我认为如果您将鼠标悬停在某个元素上,则会尝试显示和隐藏子元素,那么您可以尝试使用此代码,该代码将非常适合您的情况。
Try Demo @ http://jsfiddle.net/FTnsn/ 尝试演示@ http://jsfiddle.net/FTnsn/
$(function() { $('.thumb').hover( function() { $(this).find('.option').toggle(); }); });
Let me know if I misinterpret your problem... 如果我误解了您的问题,请告诉我...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.