What can be done to stop slideToggle from continuously triggering when hovered over multiple times?

After receiving a list of images, I noticed that Lorem Ipsum text appears every time the mouse hovers over the li elements. However, if you quickly move the mouse from one list element to another, the slideToggle function continuously activates and deactivates as many times as you hover over the elements.

In addition, when the cursor moves over the p element, which displays the text, it continues to move because it is not recognized as being over the li element, only the p. Any ideas on how to prevent this?

Check out my demo on JSFiddle

Thank you <3

$('#tabela_trabalhos ul li').mouseover(function () {
                $(this).find('p').slideToggle(200)
                
            })
            
            $('#tabela_trabalhos ul li').mouseleave(function () {
                $(this).find('p').fadeOut(400)
                
            })
#tabela_trabalhos {
                margin-top: 32px;
                position: absolute;
                right: 10px;
                left: 10px;
            }

            #tabela_trabalhos ul {
                list-style: none;
                display: flex;
            }

            #tabela_trabalhos ul li {
                width:100%;
                height:100px;
                background: #aaa;
                transition:1s;
            }

            #tabela_trabalhos ul li:hover {
                background:#888;
                transition:0.2s;
                cursor:pointer;
            }

            #tabela_trabalhos ul li p {
                display:none;
                color:white;
                margin:25px 0 0 25px;
                font-size:20px;
            }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="tabela_trabalhos">
                    <ul>
                        <li><p>Lorem Ipsum Dolor Sit Amet</p></li>
                        <li><p>Lorem Ipsum Dolor Sit Amet</p></li>
                        <li><p>Lorem Ipsum Dolor Sit Amet</p></li>
                    </ul>

                    <ul>
                        <li><p>Lorem Ipsum Dolor Sit Amet</p></li>
                        <li><p>Lorem Ipsum Dolor Sit Amet</p></li>
                        <li><p>Lorem Ipsum Dolor Sit Amet</p></li>
                    </ul>
                </div>

Answer №1

Consider using the mouseenter event instead of mouseover. You can also utilize finish() to ensure any ongoing animations are immediately stopped.

$('#tabela_trabalhos ul li').mouseenter(function () {
    $(this).find('p').finish().slideToggle(200);        
});

$('#tabela_trabalhos ul li').mouseleave(function () {
    $(this).find('p').finish().fadeOut(400);        
});

See Demo

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fade in the div based on a certain criteria

Apologies for my limited proficiency in English... Let me explain the current situation: I have a single page website with a navigation bar structured like this <ul> <li><a href="link1">#section1</a></li> <li> ...

Media query causing CSS display:none to malfunction

I'm currently working on making my website responsive, and I have a specific requirement where I need to hide an anchor when the screen size is under 850px. The code snippet I have is as follows: My goal is to display the first anchor (#tryitnow) by ...

Sending an incorrect value to Java through an Ajax call

My HTML Document contains several div elements, each with a unique Id. I have implemented a script that identifies the specific div when another element is dragged and dropped onto it. For example, if the id of the div is '5': When I alert the ...

Creating a border around a clipped box using CSS

I have a uniquely shaped box with a diagonal line at the end. I want to add a border around it, but the border also follows the shape of the box. Is there a way to apply a border to the clipped area using only CSS and HTML? So that the white part has a bl ...

The hover selector in Material UI and React is not functioning as expected

My code is experiencing an issue where the hover selector does not appear to be working. Although all other styling aspects function correctly, the hover effect is not visible. import React from "react"; import Paper from '@material-ui/core/Paper&apo ...

preserving the status of checkboxes based on an array of binary values

I am trying to figure out how to restore the state of checkboxes in an ORACLE APEX tabular form. The selection is made in the first column using the APEX row selector f01. After saving the checkbox state in a collection and then transferring it to an arra ...

Tips for positioning an inner div within an outer div

Code Snippet: <div style="width: 300px; position: absolute; right: 25%; top: 5%; -webkit-box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75); -moz-box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75);box-shadow: 2px 4px 40px 0px rgba(0,0,0,0.75);"> <secti ...

What is a simple way to center a box on a page without relying on margins?

I'm attempting to position a box in the center of the page without relying on margin. Here's what I've tried so far: .box-middle { vertical-align:middle; height:100px; width:100px; border:1px solid #ddd; } This approach h ...

Using the hide() and show() functions may result in sporadic page jumps

My table is filled with information about job listings that a user is interested in. Here's how the structure looks: <div class="container"> <table class="table-responsive table-hover table-bordered col-sm-12 col-md-6 col-md-offset-1 col ...

Learn how to efficiently insert images into a div element and then upload them to a server using AngularJs

I am currently working on developing a CRM application and have successfully integrated a feature that allows users to select a div from a range of options. There is a button provided to insert an image into the selected div, along with ng-style to define ...

Dynamic Button Creation with Ajax for Sending Post Requests

Looking for help in dynamically assigning an id to a specific element for a POST request and then applying a class to another element? I'm still learning JS, so I'm having trouble figuring it out... Essentially, my JSP page includes a forEach lo ...

Seems like the ng-show events inside are not being triggered, almost like an invisible image

I am encountering an issue where no JavaScript events are triggering inside an ng-show div in my code. You can access my code through the following link on Plnkr: http://plnkr.co/edit/kGqk8x?p=preview Upon loading data from JSON, I set ng-show to true. Ho ...

Is it advisable to avoid using XHTML elements, tags, and attributes that will not be included in the HTML 5 specification?

Given that I am currently utilizing XHTML 1.0 Strict, does it make sense to avoid using XHTML elements, tags, and attributes that are not included in the HTML5 specification? For example: <acronym> and <big> ...

Automate web interactions using Selenium to target and extract specific HTML elements

I've been making great progress on my side project, but I've encountered an issue for which I can't seem to find any specific information. My goal is to extract and store the password. HTML: <code> class="password">cai3Yeej </c ...

Text using Bootstrap positioned to the right of the breadcrumb navigation bar

Currently, I am using the default theme with Bootstrap 3. I have implemented breadcrumbs as shown below: <ol class="breadcrumb"> <li><a href="#">Home</a></li> <li><a href="#">Library</a></li> < ...

Tips for revealing or concealing the second div when hovering over the first

Although the code below is functional, there seems to be a minor issue that I haven't been able to resolve. When div2 is displayed, moving the mouse pointer within its containing links (from one link to another) causes it to disappear. Can you ident ...

Beginner experiencing website overflow problem

After completing a basic web development course, I decided to create my first homepage. While I am satisfied with how it looks on a PC or laptop, the layout gets messy on mobile devices. I tried using <meta name="viewport" content="width= ...

Troubleshooting a dynamic item with the jQuery "on" function

My jQuery script is set up to dynamically add input fields when a user interacts with the page. $(document).ready(function(){ $(".files").on('change', function() { $('.file_fields').append('<li><input ...

Disordered block elements

I am having trouble centering a div in my footer. When I try to center it, the div ends up floating on top of the footer instead. Here is the link to the codepen. footer { text-align: center; background-color: grey; position: fixed; bottom: 0; width: 100 ...

Colorbox's functionality struggles to uphold several groups simultaneously without encountering errors

I have incorporated Colorbox on this page. On the setup, I have various groups listed as groups 1 to 9. However, when clicking on the second and third items, they display correctly according to the provided code. My aim is to make everything appear in the ...