简体   繁体   中英

hover effect creates flickering

I am trying to display options on an image on hover but when I hover the displayed options keeps 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(); });

the listview code

           <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>

I used both the mouseenter and hover both create the same effect. is there away to solve this

You apply .hover() on the a only. So when you hover the a , the image appear hover your a wich mean you are not hover the a anymore. That will fire the second callback of .hover() and the image will disappear. Then again you are hover the a and it repeat infinitly.

To solve that, you just have to bind the .hover() on the parent container or on both elements.

I once got similar problem as you have got. So, to solve this problem i used mouseenter and mouseleave event.

$(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
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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