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 8744613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:52:07+00:00 2026-06-13T11:52:07+00:00

I wrote some code in jquery to loop through some images inside a div,

  • 0

I wrote some code in jquery to loop through some images inside a div, fade in to each image and then slide that image up (i have a wrapping div that has div overflow hidden which height is smaller than the image) – then fade to next image, slide up, repeat – however I need to reset the slide so that on the next loop through the image isn’t “stuck” at the top.

Everything works great in regards to fading and the FIRST slide (margin-top:-108px;) – however, when i try to reset the margin-top to 0px for the next iteration it doesn’t reset it, and on the next iteration the image is still at the -108px position.

Please excuse my Jquery code, if there are noob mistakes, i’m pretty new to it!

Here is my code:

CSS

        <style type="text/css" media="screen">
        #slider { height:296px; overflow:hidden; width:822px; position:absolute; left:50%; margin-left:-411px; top:87px; z-index:20; }
        #slider-back { position:absolute; left:50%; margin-left:-411px; height:296px; z-index:29; top:87px; width:822px; background: url("/test/backimage.png") no-repeat scroll 0px 0px transparent; }
    </style>

HTML

    <div id="slider">
        <a href="#"><img src="images/banner/Image1.jpg" id="image1" /></a>
        <a href="#"><img src="images/banner/Image2.jpg" id="image2" /></a>
        <a href="#"><img src="images/banner/Image3.jpg" id="image3" /></a>
    </div>
    <div id="slider-back"></div>

JQUERY

        <script type="text/javascript">

        $(document).ready(function() { 

            var imgs = $('#slider > a > img'); var z = 1; var previousImageId = "";

            $(imgs[0]).show();

            function loop(ev) {
                    imgs.delay(5000).fadeOut(300).eq(z).fadeIn(500, function() {

                    $(this).animate({marginTop:'-108px'}, {queue: false, duration:6000});

                    $(this).css("margin-top","0px");

                    check = z != imgs.length-1 ? z++ : z=0;

                    loop();      
                });
            }
            loop();
        });

    </script>
  • 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-13T11:52:08+00:00Added an answer on June 13, 2026 at 11:52 am

    You should reset the margin on the complete callback of the animation, otherwise the animation itself will override the margin-top you set, so do as follows:

    $(this).animate({marginTop:'-108px'}, {queue: false, duration:6000, complete: function(){
        $(this).css("margin-top","0px");
    }});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to increment through JQuery loop to fill out some HTML code with
I wrote a some jquery code and when i use that in tags, it
I wrote some jQuery code in which I was getting the width of images
I'm trying to write some jQuery code that gets the combined width of images
I'm trying to debug some code that another developer wrote in jquery since page
Below is some jQuery code the i wrote to make a simple animation. However
I wrote some code in VHDL that is expected to look at a rotory
I wrote some code that activity starts a service to get some text from
I wrote some code which monitors the output of Stopwatch using a tight loop.
I am attempting to write some jQuery code that will expand a paragraph when

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.