yugiorima123 Posted March 9, 2020 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted March 9, 2020 Share Posted March 9, 2020 vLeftButton, IconL, leftAction(), hmmm wonder why it does not work for right? A real puzzler this one. 1 Link to comment Share on other sites More sharing options...
yugiorima123 Posted March 9, 2020 Author 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😢 Link to comment Share on other sites More sharing options...
dsonesuk Posted March 9, 2020 Share Posted March 9, 2020 I think you have to work from the last child instead of first 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted March 10, 2020 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now