繁体   English   中英

悬停效果产生闪烁

[英]hover effect creates flickering

我试图在悬停时在图像上显示选项,但是当我悬停时,显示的选项一直闪烁

      $('a').hover(function(event) {
        var href = $(this).attr('href');
        var top = $(this).next().css("bottom");

            $(this).next().css("display", "block");
            $(this).next().next().css({ 'top': '30px', 'display': 'block' });

    },function() {
            $(this).next().hide();
            $(this).next().next().hide();

    });

});
$('.SelectionAnimate').hover(function() { $(this).css("display", "block"); $(this).next().show(); });

列表视图代码

           <ItemTemplate>
            <div style="float: left; position: relative; margin: 10px;" >
                <div>
                    <a class="real" href='<%#"/ProfileTenModified/UserProfile/PhotoCross.aspx?in="+ Eval("Full_Image_Name") +"&mi=" + Eval("User_Id") +"&fd="+ Eval("Album")%>'>
                        <asp:Image ID="Image1" runat="server" ImageUrl='<%#"/ProfileTenModified/setP/"+ Eval("Slide_Thumb_Name") +".JPEG" %>'
                            BorderStyle="Solid" BorderWidth="1px" Width="172px" Height="172px" />
                    </a>
                    <asp:LinkButton CssClass="SelectionAnimate" ID="Selection" runat="server" Text="Set as Display"
                        OnCommand="ListViewThums_Selection_Command" CommandName="selection"></asp:LinkButton>
                    <asp:LinkButton CssClass="SelectionAnimate" ID="Deletion" runat="server" Text="Remove"
                        OnCommand="ListViewThumbs_Command"></asp:LinkButton>
                </div>
                <asp:HiddenField ID="HiddenFieldImageId" runat="server" Value='<%#Eval("Id") %>' />
            </div>
        </ItemTemplate>

我同时使用mouseenterhover都可以产生相同的效果。 有没有解决的办法

您应用.hover()上的a而已。 所以,当你徘徊在a ,图像显示悬停你a至极意味着你不徘徊的a了。 这将触发.hover()的第二个回调,并且图像将消失。 然后再次将鼠标悬停在a ,然后无限重复。

为了解决这个问题,您只需将.hover()绑定到父容器或两个元素上。

我曾经遇到过类似的问题。 因此,为解决此问题,我使用了mouseenter和mouseleave事件。

$(selector).on('mouseenter', function(){
  //perform what you want whe mouse is on your selector
}).on('mouseleave', function(){
  //your code on when mouse leaves the selector
});

暂无
暂无

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

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