The usage of jQuery slideUp and slideDown is resulting in a bouncing animation effect

Hey there! I've been working on a cool slide up effect for an image using jQuery's slideUp and slideDown functions. It's working well, but I've noticed that when you hover over certain areas of the div/image, the effect becomes jumpy or bouncy. Below are snippets of the HTML, CSS, and JS code. I had to get creative with targeting each div due to some issues with event objects.

HTML

<div class="blog">
    <h1>Our Blog</h1>
    <ul class="blog__list">
        <li class="blog__item first">
            <div class="blog__item--heading">
                <h4>Travel</h4>
                <h3>Far far away, behind the word mountains</h3>
                <p>Wellie Clark</p>
            </div> <!-- .blog__item-heading end -->
            <div class="firstSlide"></div>
        </li>
        <li class="blog__item second">
            <div class="blog__item--heading">
                <h4>Travel</h4>
                <h3>Far far away, behind the word mountains</h3>
                <p>Wellie Clark</p>
            </div> <!-- .blog__item-heading end -->
            <div class="secondSlide"></div>
        </li>
        <li class="blog__item third">
            <div class="blog__item--heading">
                <h4>Travel</h4>
                <h3>Far far away, behind the word mountains</h3>
                <p>Wellie Clark</p>
            </div> <!-- .blog__item-heading end -->
            <div class="thirdSlide"></div>
        </li>
    </ul> <!-- .blog__list end -->
</div> <!-- .blog end -->

CSS

.blog {
    background-color: #F1F1F1;
    padding: .1rem;
}

.blog h1 {
    text-align: center;
    font-size: 3.2rem;
    margin: 11rem auto 9rem;
}

.blog__list {
    list-style: none;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 12rem;
}

.blog__item {
    background: linear-gradient(rgba(5, 5, 5, .5), rgba(5, 5, 5, .5)),
                url("../img/drinkingCoffee.png");
    background-size: cover;          
    width: 35rem;
    height: 48rem;
    margin: 0 1.7rem;
    transition: all .3s;
    position: relative;
}

.blog__item:hover h3, .blog__item:hover h4, .blog__item:hover p {
    color: black;
}

.blog__item:hover {
    cursor: pointer;
}

.blog__item--heading {
    position: absolute;
    bottom: 0;
    color: white;
    z-index: 10;
}

.blog__item--heading h4 {
    margin-left: 2rem;
    font-size: 1.3rem;
    color: lightgray;
    margin-bottom: 0;
}

.blog__item--heading h3 {
    margin: .8rem 0 0 2rem;
    font-size: 2.2rem;
}

.blog__item--heading p {
    margin: 1.2rem 0 3rem 2rem;
    color: lightgray;
    font-size: 1.3rem;
}

.firstSlide {
    background-color: white;
    height: 17rem;
    width: 35rem;
    position: absolute;
    bottom: 0;
    display: none;
}

.secondSlide {
    background-color: white;
    height: 17rem;
    width: 35rem;
    position: absolute;
    bottom: 0;
    display: none;
}

.thirdSlide {
    background-color: white;
    height: 17rem;
    width: 35rem;
    position: absolute;
    bottom: 0;
    display: none;
}

JS

// Creating slide up effect for blog divs

// first 
$(".first").on("mouseover", () => {
    $(".firstSlide").slideDown(250);
});
$(".first").on("mouseout", (evt) => {
    $(".firstSlide").slideUp(250);
});

// second
$(".second").on("mouseover", () => {
    $(".secondSlide").slideDown(250);
});
$(".second").on("mouseout", (evt) => {
    $(".secondSlide").slideUp(250);
});

// third
$(".third").on("mouseover", () => {
    $(".thirdSlide").slideDown(250);
});
$(".third").on("mouseout", (evt) => {
    $(".thirdSlide").slideUp(250);
});

Answer №1

If you want to achieve a slide up effect on blog divs, consider using the hover function instead of mouseover and mouse out events. You can find more information in the official documentation here: https://api.jquery.com/hover/

Below is a sample code snippet:

// Adding slide up effect on blog divs

// first 
$(".first").hover(function() {
    $(".firstSlide").slideDown(250);
},function() {
    $(".firstSlide").slideUp(250);
});


// second
$(".second").hover(function() {
    $(".secondSlide").slideDown(250);
},function() {
    $(".secondSlide").slideUp(250);
});


// third
$(".third").hover(function() {
    $(".thirdSlide").slideDown(250);
},function() {
    $(".thirdSlide").slideUp(250);
});
.blog {
    background-color: #F1F1F1;
    padding: .1rem;
}

.blog h1 {
    text-align: center;
    font-size: 3.2rem;
    margin: 11rem auto 9rem;
}

/* More CSS styles */

.firstSlide {
    background-color: white;
    height: 17rem;
    width: 35rem;
    position: absolute;
    bottom: 0;
    display: none;
}

/* More CSS styles */

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="blog">
    <h1>Our Blog</h1>

    /* HTML markup for blog items */
    
</div>

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

Rails is sending multiple duplicate post requests

There seems to be a strange issue with my Rails app where it is submitting two post requests in rapid succession only when I manually submit forms using jQuery. Oddly enough, if I navigate to another page and try to submit the form again, only one request ...

Sharing Angular 4 components in my project - collaboration at its finest

I have been working on an Angular project that consists of a variety of UI components. I would like to make these components available for use in other Angular projects and share them within the npm community. All of the components are located in a shared ...

What could be preventing the webpack dev server from launching my express server?

Currently working on a straightforward web application using express and react. The front-end React bundle is being served via the express server. Everything runs smoothly with my start script, which builds the front-end code and launches the express serv ...

Submitting form data as JSON using Axios' POST method

I am facing an issue while trying to send data from an HTML form to a REST backend service that only accepts JSON. After setting up my form as follows: <form name="form" > <input type="text" placeholder="Name" value="name" size="60"/></ ...

Wrapping a series of grids within a parent container to manage height effectively with grid960

Testing on the following browsers: Internet Explorer, Chrome, Firefox; Check out this example of an ideal layout in a PDF: Here is the link to the direct page: While Grid systems work well for width layout, I struggle with setting height constants. In ...

Validation and promises in the world of AngularJS

Validation of a form in an Angular app involves using a custom JavaScript function before submission. Depending on a condition, a confirmation dialog needs to be displayed to the user, requiring them to confirm or reject it before proceeding with validatio ...

How can you direct a CSS transition towards a pseudo-element named "Arrow"?

I designed a DIV with a unique "arrow" feature at the bottom, resembling a speech bubble commonly seen in comic books, which appears when hovered over: The arrow effect is achieved using the :after and :before pseudo-elements. For the hover state, I incl ...

Tired of searching for a way to activate the Inspect function in the right-click menu on a custom dialog while debugging Google apps

I'm currently working on implementing a file picker function within Google Sheets by using the Google Picker API. Although I have managed to display a customized dialog window for selecting files from my Google Drive, the output is not exactly what I ...

Implementing React Localized Global Styling

Is there a way to confine the global styles of a module to just one file? For example, I want to adjust the width of an element in a react module but only within one specific file. Unfortunately, inline styles are not an option :/ Edit for clarification: ...

Choose all the HTML content that falls within two specific tags

Similar Question: jquery - How to select all content between two tags Let's say there is a sample HTML code as follows: <div> <span> <a>Link</a> </span> <p id="start">Foo</p> <!-- lots of random HTML ...

incapable of modifying the contents of an array

Struggling with a JavaScript issue (not angular related, but within an Angular context) for hours without any success. I've condensed the content into shorter paragraphs and reassigned the subcontent back to the array's content property, but the ...

How can data be effectively passed between templates in Angular?

I have two templates: in the first template, I am using a function and after its successful execution, I want to retrieve data in the second template. How can I achieve this? Both templates are utilizing the same controller. First Template: <form ng-s ...

Align two images to the center while displaying them in individual rows

<div class="client-logo-wrapper"> <a href="some link"><img class="client-logo" src="images/logo.png" alt="client-logo"></a> <a href="some link"><img class="contract-logo" src="images/logo.png" alt="contr ...

Jquery Fails to Execute When Clicking on Radio Button

Whenever a user selects a radio button, I want to display an alert box. I have already written the jQuery code to achieve this. Here is my implementation: <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></ ...

Compel a customer to invoke a particular function

Is there a way to ensure that the build method is always called by the client at the end of the command chain? const foo = new Foo(); foo.bar().a() // I need to guarantee that the `build` method is invoked. Check out the following code snippet: interface ...

Developing a synchronous loop in Node.js using the web-kit module

My goal with my app using node.js and webkit is to scan each proxy listed in a file.txt and determine if the proxy is working. However, I am encountering an issue where my loop does not wait for the "http.get" test on line 11 to complete before moving on ...

Determine the height of the left div, which is set to auto, and apply the same height to the right div, which has overflow set

I am facing an issue that needs a solution. I need to ensure that two div elements have the same height. The left div should have 'auto' height while the right one must match it. Moreover, the right div contains 14 nested divs that need to be scr ...

Tips on properly updating a property of a state object in ReactJS using the useEffect hook for functionality

I have a snippet of code that initializes some data: const userData = useSelector(state => state.userData); // Get from redux state const [formData, setFormData] = useState({ userId : '', ...

Traverse Through Collection of Vue Elements

I am working on creating an array of Vue Components based on a configuration file containing various UI sections to display; const config = [ 'summarySection', 'scoreSection', 'educationSection' ] I am attempting to ma ...

Dual-tone border design

Is it possible to create a double border effect with one color on top and another color on the bottom using CSS? I'm trying to recreate an image with a border that has two different colors on different parts of the width using only CSS: ...