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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:21:16+00:00 2026-06-17T22:21:16+00:00

I’m creating an auto_play loop function to have slides slide infenitly. But I’m having

  • 0

I’m creating an auto_play loop function to have slides slide infenitly.
But I’m having problems when the variable slidePosition is equal to 1 the if function that validates that won’t trigger.

html

<div class="slide_wrap">
    <div class="slides">
      <ul>
        <li><img src="images/img_01.jpg"/></li>
        <li><img src="images/img_02.jpg"/></li>
        <li><img src="images/img_03.jpg"/></li>
      </ul>
</div></div>

js

$(".slides").bind("auto_play.loop", function(){
if(slidePosition == 1){<br/>
$(this).delay(1000).animate({right:'+='+slideWidth, easing: 'swing'}, 1000);<br/>
slidePosition = 2;<br/>
        }<br/>
        if(slidePosition == 2){<br/>
            $(this).delay(1000).animate({right:'+='+slideWidth, easing: 'swing'}, 1000);<br/>
            slidePosition = 3;<br/>
        }<br/>
        if(slidePosition == 3){<br/>
            $(this).delay(1000).animate({right:'-='+2*slideWidth, easing: 'swing'}, 1000);<br/>
            slidePosition = 1;<br/>
        }<br/>
        trigger("auto_play.loop");<br/>
    }).trigger("auto_play.loop");
  • 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-17T22:21:18+00:00Added an answer on June 17, 2026 at 10:21 pm

    Alright I think your issue was your if statements. Inside each you would need to call and else if, otherwise the slidenumber would be set and the next if statement would run.

    After reviewing the code I understand what your trying to accomplish took your approach and cleaned it up a little. Instead of calling jquery triggers I moved those into method calls. Now after each animation is completed it will call the Update function to get the next animation in the sequence, much cleaner and easier to maintain.

    There are still things that need cleaned up. Such as making it take an infinite amount of slides. Right now its hard coded to only do three. While that works it would be good to abstract out the count, and have it read the dom and get a count that way.

    You can view the solution on jsFiddle here

    Update:
    Modified the javascript to take an unlimited amount of slides. I suggest you use this type of approach so you can keep adding slides and never touch an ounce of javascript.

    Updated Fiddle

    Javascript:

    $(document).ready(function()
                      {
                          //On page load initialize the slideshow
                          MyApp.SlideShow.init();
                      });
    //create a namespace for our code
    var MyApp = MyApp || {};
    
    //create a function inside a closure to handle all slideshow functions
    MyApp.SlideShow = (function ()
    {
        var slidePosition = 1;
        var slideWidth = 100;
        var slider = $('.slides');     
    
        //called when page is loaded
        function init()
        {
            var v = $('.viewer');      
            var vtop = v.position().top;
            vleft = v.position().left;    
            //Set the slider to where the view is 
            slider.css('left', vleft).css('top', vtop);
            update();
        };
    
        //function to update the slide block
        function update()
        {
            if (slidePosition == 1) {
                slider.delay(1000).animate({
                    left: '-=' + slideWidth,
                    easing: 'swing'
                }, 1000, update);
                slidePosition = 2;
            }
            else if (slidePosition == 2) {
                slider.delay(1000).animate({
                    left: '-='+ slideWidth,
                    easing: 'swing'
                }, 1000, update);
                slidePosition = 3;
            }
            else if (slidePosition == 3) {
                slider.delay(1000).animate({
                    left: '+=' + 2 * slideWidth,
                    easing: 'swing'
                }, 1000, update);
                slidePosition = 1;
            }
        };    
        return {
            init: init
        };
    }());
    

    HTML:

    <div class="slide_wrap">
        <div class="slides">
          <ul>
            <li class="s1">1</li>
            <li class="s2">2</li>
            <li class="s3">3</li>
          </ul>
        </div>
    </div>
    
    <div class="viewer"></div>
    

    CSS:

    .viewer
    {
        border:5px solid yellow;
        height:100px;
        width:100px;
        position:absolute;
        top:100px;
        left:300px;
    }
    .slides li
    {    
     height:100px;
     width:100px;
    float:left;
    }
    .slides ul
    {    
      height:100px;
    }
    .slides
    {
        position:absolute;
    }
    .s1
    {
      background-color:red;  
    }
    .s2
    {
      background-color:blue;  
    }
    .s3
    {
      background-color:green;  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I want to construct a data frame in an Rcpp function, but when I
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

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.