Javascript fade in fade out without Jquery and CSS3

前端 未结 6 524
南方客
南方客 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:30

    element.style is undefined because you're not referencing the correct object. Use element[0] for your function call:

    function handleClick(evt){     
        var element = document.getElementsByClassName(evt.target.id);
        fade(element[0]);        
    }
    

    Fiddle



    Side note: Using console.log() and some type of developer console (like the one included in Chrome) can work wonders for debugging.

提交回复
热议问题