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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:15:37+00:00 2026-05-27T18:15:37+00:00

I have this small script that changes the background image with a fadein/out effect:

  • 0

I have this small script that changes the background image with a fadein/out effect:

/*controla la velocidad de la animación*/
    var slideshowSpeed = 1000;
    var transitionSpeed = 2000;
    var timeoutSpeed = 500;
    
    /*No tocar*/
    var interval;
    var activeContainer = 1;    
    var currentImg = 0;
    var animating = false;
    var navigate = function(direction) {
        // Si ya estamos navegando, entonces no hacemos nada!
        if(animating) {
            return;
        }
        currentImg++;
        if(currentImg == photos.length + 1) {
            currentImg = 1;
        }
        // Tenemos dos, uno en el que tenemos la imagen que se ve y otro d?nde tenemos la imagen siguiente
        var currentContainer = activeContainer;
        // Esto puedo optimizarlo con la funci?n modulo, y cambiar 1 y 2 por 0 y 1-> active = mod2(active + 1)
        if(activeContainer == 1) {
            activeContainer = 2;
        } else {
            activeContainer = 1;
        }
        // hay que decrementar el ?ndice porque empieza por cero
        cargarImagen(photos[currentImg - 1], currentContainer, activeContainer);
    };
    var currentZindex = -1;
    var cargarImagen = function(photoObject, currentContainer, activeContainer) {
        animating = true;
        // Nos aseguramos que el nuevo contenedor está siempre dentro del cajon
        currentZindex--;
        /*if(currentZindex < 0) currentZindex=1;*/
        // Actualizar la imagen
        $("#headerimg" + activeContainer).css({
            "background-image" : "url(" + photoObject + ")",
            "display" : "block",
            "z-index" : currentZindex
        });
        // FadeOut antigua
        // Cuando la transición se ha completado, mostramos el header 
        $("#headerimg" + currentContainer).fadeOut(transitionSpeed,function() {
            setTimeout(function() {
                
                animating = false;
            }, timeoutSpeed);
        });
    };
    
function iniciarPase(){
    var animating = false;
    //ver la siguente
     navigate("next");
    //iniciar temporizador que mostrará las siguientes
    interval = setInterval(function() {
        navigate("next");
    }, slideshowSpeed);
}
function pararPase(){
    var animating = true;
    console.log('paramos la animación');
    interval = clearInterval(interval);
}
/*Gestion de pase de imágenes de fondo*/
$(document).ready(function() {
    iniciarPase();
});

But the function pararPase() which contains the clearInterval expression seems not to work even if its on the <body onload="pararPase()">

Any idea what I am missing?

  • 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-05-27T18:15:37+00:00Added an answer on May 27, 2026 at 6:15 pm

    Your base logic is working just fine, here is live test case.

    So most likely you bind pararPase incorrectly, for example trying to bind as click handler outside document.ready() when the button does not yet exist – updated test case to prove this point.

    Another option is other error in your code, check Chrome JavaScript console to see if this is the case.

    As others mentioned in comments, assigning the return value of clearInterval back to the variable is meaningless, but not harmful: the variable will just have the value “undefined”.

    Edit: there is a chance that iniciarPase is called more than once, this will cause more than one timers where only the last will be cleared. So, to be on the safe side add this to your function: (that’s actually what Diode tried to say in his answer)

    function iniciarPase(){
        var animating = false;
        //ver la siguente
        navigate("next");
        //iniciar temporizador que mostrará las siguientes
        if (interval)
            clearInterval(interval);
        interval = setInterval(function() {
            navigate("next");
        }, slideshowSpeed);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small jquery script that does not work if I remove the
I have this small PHP script: <?php session_start(); $var = array(); $var['key'] = 'Var
I have this small code library that I'm considering releasing into Open Source. I
I have this small class called City that simply holds some information about a
I have this nifty little script that does a nice job of manipulating some
I have a script that will output a jpg, gif or png image. It
Here I have a small VBS script that helps me append a new line
I have a script that animates a small DIV popping up on the page.
I have a small script that I use to resize all of the images
I have a small javascript that changes the title of a input-field to it's

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.