javascript - Setting Variables Does Not Work on Page Load, but Does Through Console? -
i must missing something. script follows:
var slideshowul = jquery('div.slideshow').css('overflow', 'hidden').children('ul'), imgs = slideshowul.find('img'), imgwidth = imgs[0].width, imgslen = imgs.length, current = 0; console.log(slideshowul); console.log(imgs); console.log(imgwidth); console.log(imgslen); console.log(current);
the output is:
[ul, prevobject: p.fn.p.init[1], context: document, selector: "div.slideshow.children(ul)", constructor: function, init: function…] [img, img, img, img, prevobject: p.fn.p.init[1], context: document, selector: "div.slideshow.children(ul) img", constructor: function, init: function…] 0 4 0
it not getting width of image. when paste above code directly console, returns correct value (750).
width of 0 means reading value before images have loaded. call on window onload , not ready/inline.
Comments
Post a Comment