slideshow: js is not working

0

I'm trying to create a slideshow, as stated in the title, but in js the style.width property does not accept the value of the slidewidth variable. The error that appears in the console: "Uncaught TypeError: Can not set property 'width' of undefined at window.onload"

Follow the JSfiddle link with the source code: link

    
asked by anonymous 23.02.2018 / 14:21

1 answer

0

Objs was selecting by tag name, not by class and lacked putting "px" in equality. Your corrected code is this:

window.onload = function(){
    var slideWidth = document.getElementById("slideshow").offsetWidth;
    var objs = document.getElementsByClassName("slide");
    for(var i = 0; i < objs.length; i++){
        objs[i].style.width = slideWidth+"px";
    }
}   

Enjoy and switch:

<meta id="viewport" name="viewport" content="widht-device-witdth, user-scaleble=no">

By:

<meta name="viewport" content="width=device-width, user-scalable=no">
    
23.02.2018 / 14:35