Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8241013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:41:20+00:00 2026-06-07T20:41:20+00:00

I am having issues with jQuery animations on a really simple slider. The first

  • 0

I am having issues with jQuery animations on a really simple slider. The first time you click on them the animation seems buggy. The animations make the divs break the container. I add overflow: hidden to the containing div, but it just makes the content ‘flash’ instead of overflow underneath.

After the first click of each element, the animations are fine. Any idea how to avoid this behaviour?

Here is the example: http://jsbin.com/izuviv/edit#preview

HTML

<div id="slider">
    <div class="slide expanded">
        <img />
        <a href="">
            <h3>Lorem</h3>
            <p>Ipsum</p>
        </a>
    </div>
    <div class="slide">
        <img />
        <a href="">
            <h3>Lorem</h3>
            <p>Ipsum</p>
        </a>
    </div>
    <div class="slide">
        <img />
        <a href="">
            <h3>Lorem</h3>
            <p>Ipsum</p>
        </a>
    </div>
    <div class="slide last">
        <img />
        <a href="">
            <h3>Lorem</h3>
            <p>Ipsum</p>
        </a>
    </div>
</div>

CSS

#slider {width: 632px; height: 231px; margin: 100px; font-family: arial, helvetica, sans-serif;}
    #slider .slide {width: 71px; height: 231px; background: black; margin: 0 4px 0 0; float: left; display: inline; position: relative;}
        #slider .slide a {display: block; width: 71px; height: 72px; background: transparent url(../img/white.png) 0 0 repeat; text-decoration: none; color: #000; position: absolute; bottom: 0;}
        #slider .slide h3 {display: none;}
        #slider .slide p {display: none;}

    #slider .last {margin: 0;}
    #slider .expanded {width: 407px;}
        #slider .expanded a {width: 407px; background: transparent url(../img/white.png) 0 0 repeat;}
        #slider .expanded h3 {margin: 10px 10px 0px 10px; font-size: 14px; font-weight: bold; display: block;}
        #slider .expanded p {margin: 5px 10px; font-size: 12px; display: inline;}

JS

function slider() { 

    var slide = $('#slider div');

    slide.click(function(){

        var expanded = $('#slider .expanded');

        if (!$(this).hasClass('expanded') ) {

            // 1: Shrink expanded div
            expanded.animate({
                width: '71px'
            }, 200, function() {
                console.log('contract');
                // 2: Remove expanded class
                $(this).removeClass('expanded');
            });

            // 3: Add expanded class to clicked
            $(this).addClass('expanded');

            // 4: Expand clicked div
            $(this).animate({
                width: '407px'
            }, 200, function() {
                console.log('expand');
            });

        }

    });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:41:23+00:00Added an answer on June 7, 2026 at 8:41 pm

    In the Function Slider, i changed the code into:

    $('.slide').click(function (){
        $this = $(this);
        if(!$this.hasClass('expanded')){
          $exp = $('.expanded');
          $exp.animate({width:'71px'},200,function (){$exp.removeClass('expanded');});
          $this.animate({width:'407px'},200).addClass('expanded');
        }
    });
    

    Now, it works fine..
    I think what cause the problem is: $(this);.. Always save this into a variable to prevent errors and duplicates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having issues with jQuery selectors (again). I'm sure this is really simple but
I am having jQuery animation issues... I have a footer with a hidden div
I am having issues with loading external javascript using JQuery. Every time when I
I'm using the DataTables jQuery plugin and am having issues with the First and
I'm having issues with my jQuery code. When I click the button everything within
So I'm just trying to do a simple jquery effect but am having issues
I am having issues with my jQuery animation using elastislide as you can see
I'm having issues with multiple jQuery dialogs. The first one opens fine - is
I am having issues triggering a jQuery click through Greasemonkey/Tampermonkey... jQuery('button').each(function() { jQuery(this).css('background', 'red');
I am having issues with jquery-autocomplete if i start typing then the results /

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.