The mouseover animation doesn't reset to its original position during quick movements, but instead continues to move without interruption

Greetings! Welcome to my live page.

Currently, I am facing an issue with the sliding animation on the header. Specifically, the small gray slide-up divs at the bottom of the sliding pictures are not behaving as expected. They are meant to slide up on mouseover and then return to their original position once the mouse moves away, which they do on slow movements.

The animation code is as follows:

sub_div.animate({top:"-=20"},500);})

And the reset code is:

    $('.sub').hide();
    $('.sub').css('top','190px' );

Despite resetting their position at the start of the code, when I quickly move the mouse on and off the pictures, the title divs continue to appear. I attempted to use:

sub_div.stop(true).animate({top:"-=20"},500);})

However, this approach did not resolve the issue.

In the HTML, the divs with the "pics" class represent the sliding divs, while the divs with the "sub" class are the small title divs at the bottom.

<div id="wrapper">
    <div class="pics" id="pic1"><div class="sub">cccc</div></div>
    <div class="pics" id="pic2"><div class="sub">mmm</div></div>
    <div class="pics" id="pic3"><div class="sub">mmmm</div></div>
    <div class="pics" id="pic4"><div class="sub">mmm</div></div>
    <br  class="clearfloat"/>
</div>

Here is the jQuery function:

<script language="javascript">

$(function(){

        $('.pics').mouseover(function(){

        /* Resetting all the sub divs at the bottom to default */

        $('.sub').hide();
        $('.sub').css('top','190px' );

        /* Resizing all divs to 86px except the one being mouseovered */

        $('.pics').not(this).stop(true).animate({width:"86"},500 )

        /* Setting the div being mouseovered to 400px */

        $(this).animate({width:"400"},500 , function(){

            /* Sliding up the little title div at the bottom */

            var sub_div = $(this).find('.sub');
            sub_div.show();
            sub_div.animate({top:"-=20"},500);})
         })
})
</script>

Another issue I am facing is that the small title divs appear outside their parent div. I want them to be visible only within their parent div's area. I tried setting the parent div's overflow to hidden, but it seems this doesn't work with absolute positioning.

Below is my CSS:

/* Slides parent div */
.container .header .top_pics {
    background-color: #F5D80A;
    position: relative;
    padding-bottom: 30px;
    padding-left: 20px;
    float: left;
    width: 680px;
}

/* Sliding pictures (divs) */
.container .header .top_pics .pics {
    width: 86px;
    float: left;
    height: 200px;
    overflow: hidden;
}

/* Small slide-up titles */
.header .top_pics .sub  {
    background-color: #CCC;
    position: absolute;
    width: 395px;
    top: 200px;
    opacity: 0.5;
    display: none;
    padding-left: 5px;
    padding-top: 9px;
    padding-bottom: 9px;
}

/* Individual sliding pics */
.header #pic1 {
    width: 400px;
    background-image: url(images/h1.jpg);
    background-repeat: no-repeat;
}
.header #pic2 {
    background-color: #0C9;
}

.header #pic3 {
    background-color: #C30;
}

.header #pic4 {
    background-color: #CCC;
}

Answer №1

The issue lies in the relative animation of the top property (-=20). Consider modifying it to a specific pixel value for a smoother animation effect. For instance, if the initial value is top: 190px, adjust your animate function to

sub_div.animate({top:'170px'},500);})
.

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

What is the best way to halt all ongoing animations in jQuery before starting a new one?

I've been playing around with jQuery to achieve a cool effect. Basically, I have an image that fades into another image when you hover over a link, and then fades back when you move your mouse away. It's working well, but if you move your mouse ...

Implementing Laravel Ajax Cart Functionality

I am currently facing an issue while attempting to add items to my cart using AJAX in Laravel as I encountered error 419 (unknown status). Below is the AJAX code I have implemented: function btnAddCart(param) { var product_id = param; var url = "{{ r ...

The request is being redirected to an invalid destination, resulting in

I am facing an issue with a simple Jquery dialog box on my website. The dialog contains a button that sends the page to the server for processing. However, after some checking, the server redirects the page to another link. The problem arises when I use r ...

Exploring ways to incorporate new data into a JSON array using PHP?

After sending 4 inputs via Ajax to a php file, I am wondering how to load a JSON file and then add new data with PHP. <input type="text" id="name"> <input type="text" id="surname"> <input type="text" id="mobile"> <input type="text" id ...

Is there a way to use jQuery to determine if the selectAll checkbox is selected after manually selecting all checkboxes?

How can I accomplish this task? I believe I am capable of doing it. <input type='checkbox' id='selectAll'/> <input type='checkbox' id='select1' class='select'/> <input type='checkbox&apo ...

Tips for accessing the form file field in jQuery to successfully upload an image

My HTML code is laid out as follows: This particular form enables you to submit a file to the server.<br> <div class="imguploadpath" style="width:100%;height:200px;background-color:#CCC;"> <form name="myFormName" id ="myFo ...

Positioning elements vertically and float them to the left side

I'm struggling to grasp the concept of the float attribute. Here's the code that is causing me confusion: #p1 { border: solid black 3px } <p id="p1" style="float:left">Paragraph 1</p> <a href="https://facebook.com" style="floa ...

Utilizing the power of Vue 2 and NuxtJS to effortlessly customize the appearance of child components

I am currently working on a Nuxt.js project (still using Vue 2) that consists of two components. I am trying to override the child style with the parent's style, but the ::v-deep pseudo selector doesn't seem to be effective. Regardless of my eff ...

The Calibri Light font is not supported by Chrome version 37

Yesterday my website was working fine, but today when I checked it, some strange issues appeared. The Calibri Light font that I used extensively has been replaced with the default font, and the width of input fields has changed. How can I resolve this issu ...

Challenges encountered while working with OpenWeather API

I created a weather prediction web application using p5.js. It functions perfectly on my local server. However, I keep encountering this issue on the GitHub page: Mixed Content: The page at '' was loaded over HTTPS, but requested an insecure ...

Is it necessary for HTML "buttons" to follow the same box-model as other elements?

I recently encountered an issue with the button element and the input element when using a type of button. In both Firefox and Chrome, I noticed a behavior that seems like a bug in recent releases. However, as form elements often have exceptions to W3 rule ...

Unable to alter the height of the element

I am attempting to resize an element by dragging, similar to this example. I have created a simple directive for this purpose: @Directive({ selector: '[drag-resize]' }) export class DragResizeDirective { private dragging: boolean; const ...

Tips for positioning a Div element in the center of a page with a full-page background

I am trying to center align my div containing login information on the webpage. The static values seem to work fine, but I am looking for a way to position it dynamically. Additionally, the background is only covering a strip with the height of the div... ...

Dealing with unsuccessful ajax responses

My ajax request is not handling errors correctly. Earlier, the "r" was <br /> <b>Warning</b>: simplexml_load_string() [ <a href='function.simplexml-load-string'> function.simplexml-load-string and it did not ...

What is the best way to align bars at the bottom of a CSS vertical bar chart?

Currently, I am exploring the functionality of two distinct bar charts that I designed using HTML and CSS: one horizontal and the other vertical. Is there a way to shift the bars in my vertical bar chart from the center down to the bottom? https://i.sstat ...

Utilizing jQuery's extend method for object inheritance in a function

I've been experimenting with using jquery extend to simulate inheritance, but it seems that it only works with objects based on my testing. My goal is to achieve the following: var baseDefinition = function() { var self = this; self.calc1 = ...

Reacting to each change event, Angular dynamically loads new autocomplete options

I am facing an issue with my form where users need to select a company using mat-select-search. Upon selection, an API call is made with the selected company ID to fetch users from that company for the autocomplete feature in recipient fields. The process ...

Disregarding boundaries set by divisions

Trying to keep things concise here. I have a division called "the box" with a fixed width of 1200px that contains various other divisions. One of these divisions is a links bar, known as the "pink bar", which has a width of 100% and a height of 25px. My is ...

The image on the landing page is not properly scaling to fit the size requirements

Currently utilizing Bootstrap Studio, I incorporated the code background-size:cover. While it works well in desktop mode, it unfortunately isn't very mobile-friendly. Below are screenshots for reference: Mobile View Example Desktop View Example ...

Opting for PHP over JSON for the instant search script output

Is there a way to modify my Google Instant style search script, written in jQuery, to retrieve results from a PHP script and output PHP-generated HTML instead of JSON? Below is the current code: $(document).ready(function(){ $("#search").keyup(functi ...