yugiorima123 0 Posted March 9, 2020 Report Share Posted March 9, 2020 (edited) How can we create carousel image slider using Javascript ? i Im used <script > var vLeftButton = document.getElementById("iconL"); //var t = setInterval(leftAction,1000); function leftAction(){ var myImgs = document.getElementById("divImg"); var child = myImgs.children[0]; //alert(child.src); myImgs.removeChild(child); myImgs.appendChild(child); } var vRightButton = document.getElementById("iconR"); function rightAction(){ var myImgs = document.getElementById("divImg"); var child = myImgs.children[0]; //alert(child.src); myImgs.removeChild(child); myImgs.appendChild(child); } </script> I mean: leftbutton move to left but right button don't move to right I'm amateur😢 Edited March 9, 2020 by yugiorima123 Quote Link to post Share on other sites
dsonesuk 921 Posted March 9, 2020 Report Share Posted March 9, 2020 vLeftButton, IconL, leftAction(), hmmm wonder why it does not work for right? A real puzzler this one. 1 Quote Link to post Share on other sites
yugiorima123 0 Posted March 9, 2020 Author Report Share Posted March 9, 2020 3 minutes ago, dsonesuk said: vLeftButton, IconL, leftAction(), hmmm wonder why it does not work for right? A real puzzler this one. <script > var vLeftButton = document.getElementById("iconL"); //var t = setInterval(leftAction,1000); function leftAction(){ var myImgs = document.getElementById("divImg"); var child = myImgs.children[0]; //alert(child.src); myImgs.removeChild(child); myImgs.appendChild(child); } var vRightButton = document.getElementById("iconR"); function rightAction(){ var myImgs = document.getElementById("divImg"); var child = myImgs.children[0]; //alert(child.src); myImgs.removeChild(child); myImgs.appendChild(child); } </script> mean: but right button don't move to right I'm amateur😢 Quote Link to post Share on other sites
dsonesuk 921 Posted March 9, 2020 Report Share Posted March 9, 2020 I think you have to work from the last child instead of first 1 Quote Link to post Share on other sites
dsonesuk 921 Posted March 10, 2020 Report Share Posted March 10, 2020 </pre> <table> var child = myImgs.children; //alert(child.src); myImgs.insertBefore(child[0],child[child.length-1]); myImgs.removeChild(child.length-1); } </table> <p> </p><p 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.