Javascript fade in fade out without Jquery and CSS3

前端 未结 6 543
南方客
南方客 2020-12-03 11:28

I am really squeezing my head to make the simple fade in and fade out of the background image work only with javascript without JQuery and CSS3. I know how easy is to call a

6条回答
  •  难免孤独
    2020-12-03 11:53

    I'll point you off in the right direction and leave the rest of the coding to you.

    This is how the setInterval() function works. It takes a function to execute and then the milliseconds it should run for.

    setInterval(function() {
        if(fade(element[0]))
            clearInterval();
    }, 50);
    

    I made a JS fiddle for you here It's semicomplete but shows off how you should go about making your fadeout/fadein. This is tested in Chrome on a Mac. Not sure about FF nor IE unfortunately.

    Also as several pointed out, when getting stuff by any function that ends with s you can be 100% sure that it gives you an array with elements and thus you have to refer to the element you want as such. In your case its element[0].

    Hope I help you further a little ways! :) Good luck!

提交回复
热议问题