+ 1

why this image does not appear

i am making a slide image automatically or manually by clicking the next and previous button but the image does not appear only white color, please help me solve this problem and give me explanation why this problem can happen https://code.sololearn.com/W299dUpsstCV/?ref=app

5th May 2018, 6:57 AM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
10 Réponses
+ 1
Here is clean working code, using for of instead of loop. This way you only need to add urls to your array and it will keep working. Also page will not render until it is ready, so now you can set what ever interval you want https://code.sololearn.com/WCXE21oDq9pT/#html
5th May 2018, 8:04 AM
Mike Choy
Mike Choy - avatar
+ 1
hmm strange will post you new code
5th May 2018, 7:46 AM
Mike Choy
Mike Choy - avatar
+ 1
Mike Choy ok my code is working well it turns me too fast set up time in its setInteval thanks for helping me and answer my question.
5th May 2018, 7:53 AM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
+ 1
Ah yes the issue is that the document has not been rendered on the first loop before you try to set the URL. This is an issue with Sololearn, you really need to wrap your code in a window.onload = function() {} so that it only renders when the document is ready
5th May 2018, 7:58 AM
Mike Choy
Mike Choy - avatar
+ 1
wow thank you Mike Choy
5th May 2018, 8:07 AM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
0
Hi hafizd21j see below working code var photosPack = ["https://image.ibb.co/jdHjtn/matteo_vistocco_424475.jpg","https://image.ibb.co/dRdPtn/tersius_van_rhyn_228779.jpg","https://image.ibb.co/mQC0Yn/nick_morrison_325805.jpg"]; var indexImg = 1; var imgId=document.getElementByID("imgcontent"); function slideImg(){ if(indexImg == photosPack.lenght){ indexImg = 0; }else{ imgId.setAttribute("src",photosPack[indexImg]); indexImg++; } } var setWaktu = setInterval(slideImg,200);
5th May 2018, 7:21 AM
Mike Choy
Mike Choy - avatar
0
Mike Choy your code does not work even appear error
5th May 2018, 7:28 AM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
0
Wow I learnt something too, I did not know you could just use the elements ID inside JS without doing a document.getElementByID, many thanks!
5th May 2018, 8:08 AM
Mike Choy
Mike Choy - avatar
0
Mike Choy oh ok i also know that when i see tutorial how to make slide gallery images fron youtube i also think the same as you
5th May 2018, 8:12 AM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
5th May 2018, 8:29 AM
Yugabdh
Yugabdh - avatar