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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:30:04+00:00 2026-05-31T07:30:04+00:00

I am facing problems with this javascript code. It does a fade every 6

  • 0

I am facing problems with this javascript code. It does a fade every 6 seconds between background and foreground div, to create an slider. It works perfectly on Firefox 9 and probably in lower versions, and I have test that it really works in IE7, IE8 and IE9.

But in chrome it just do the first fading, then the image stays static. Here is the javascript code:

function start_slider () {
    var imgArr = new Array( // relative paths of images
        '/solteros/img/slider/barrancos.png',
        '/solteros/img/slider/karts.png',
        '/solteros/img/slider/parque.png',
        '/solteros/img/slider/canoaraft.png',
        '/solteros/img/slider/paintball.png',
        '/solteros/img/slider/quads.png',
        '/solteros/img/slider/rafting.png'
    );

    var preloadArr = new Array();
    var i;

    /* preload images */
    for(i=0; i < imgArr.length; i++){
        preloadArr[i] = new Image();
        preloadArr[i].src = imgArr[i];
    }

    var currImg = 0;
    var intID = setInterval(changeImg, 3000);
    var hs = document.getElementById ( 'header_slider' );    
    var hsb = document.getElementById ( 'header_slider_bkg' );
    if ( hs.style.opacity != 1 ) {
         hs.style.opacity = 1; 
    }

    var foInt = null;
    var fiInt = null;
    var imgUrl = "";

    function changeImg () {
        clearInterval ( intID );
        currImg = ( currImg < preloadArr.length-1 ) ? currImg+1 : 0;
        imgUrl = preloadArr[currImg].src;
        hsb.style.background = 'url('+imgUrl+') top center no-repeat';
        foInt = setInterval ( fadeOut, 50 );
    }

    function fadeOut () {
        if ( hs.style.opacity <= 0 ) {
            clearInterval ( foInt );
            hs.style.background = 'url('+imgUrl+') top center no-repeat';
            hs.style.opacity = 1;
            hs.style.filter = 'alpha(opacity=100);'; /* Para IE8 y anteriores */
            intID = setInterval (changeImg, 6000);
        } else {
            hs.style.opacity -= 0.05;
            hs.style.filter = 'alpha(opacity='+(Math.round(hs.style.opacity * 100))+');'; /* Para IE8 y anteriores */
        }
    }
}

Now, the CSS involved:

#header_slider_bkg {
    width: 1000px;
    height: 410px;
    min-height: 410px;
    margin: 0;
    padding: 0;
    float: left;
    background: url('/solteros/img/slider/rafting.png');
}

#header_slider {
    width: 1000px;
    height: 410px;
    min-height: 410px;
    margin: 0;
    padding: 0;
    float: left;
    background: url('/solteros/img/slider/rafting.png');
}

And so, the HTML:

    <div id="header_slider_bkg">
        <div id="header_slider">
        </div>
    </div>
    <script type="text/javascript">
        start_slider ();
    </script>

The question obviusly is why this fails on Chrome while it works in every other major browsers???

TIA

  • 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-31T07:30:05+00:00Added an answer on May 31, 2026 at 7:30 am

    After installing Chrome Developer Tools and do a bit of debugging, I have found that seems for me like a bug on Chrome javascript engine.

    The property hs.style.opacity starts with 1. The first time it does:

    hs.style.opacity -= 0.05
    

    It takes an expected value of 0.95. But the second time it gets 0.899999999999999 instead of 0.90 as expected. The loop continues until it gets a value of 0.4999…9684, then it seems to refuse to subsctract 0.05 so the fadeOut interval it is never clear because hs.style.opacity never reach a value of 0 or below.

    A quick fix seems to be changing:

    if ( hs.style.opacity <= 0 )
    

    by

    if ( hs.style.opacity < 0.5 )
    

    But this shows a wider gap between images at last change, so a better solution may be to round the value to two decimals after substraction, so I try a new approach that works fine:

    Changing:

    hs.style.opacity -= 0.5;
    

    By:

    aux = Math.round(hs.style.opacity * 100);
    aux -= 5;
    hs.style.opacity = aux / 100;
    

    So this is SOLVED.

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

Sidebar

Related Questions

I am currently facing an error in JavaScript. The code is given below function
I am new to JavaScript. I am facing a problem with my javascript code.
I am facing a problem with the java-script code... html: <div id=thumbs> <a href=link1.htm><img
I'm facing this problem again and again, but can't find any solution (except mine,
I am facing this problem upon pushing my app to Heroku: 500 internal server
I'm currently facing this problem with ruby on rails 3, devise and facebook oauth.
I was facing this unique problem of generating a bit-mask based on the input
I am facing the problem while inserting data this way. How to insert data
I'm facing a problem with IE6. I took the toggle function from this website
I am facing a problem while creating a static cursor in DB2. This is

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.