eduard Posted June 18, 2012 Share Posted June 18, 2012 To changes the images of my website (www.eduardlid.net) after a certain time, I can use the setInterval () method of JavaScript? If so, where do I find how to do this (images)? Link to comment Share on other sites More sharing options...
astralaaron Posted June 18, 2012 Share Posted June 18, 2012 something like this // imgId is the id of the image you want to change// newSrc is the new image pathfunction swapImg(imgId,newSrc){elm = document.getElementById(imgId);elm.src = newSrc;return true;}//pre load the imagevar img5=new Image();img5.src="myImage.jpg";// mouse over example<img src="someImage.jpg" onmouseover="swapImg(this.id,img5.src);" /> Link to comment Share on other sites More sharing options...
eduard Posted June 18, 2012 Author Share Posted June 18, 2012 something like this// imgId is the id of the image you want to change// newSrc is the new image pathfunction swapImg(imgId,newSrc){elm = document.getElementById(imgId);elm.src = newSrc;return true;}//pre load the imagevar img5=new Image();img5.src="myImage.jpg"; // mouse over example<img src="someImage.jpg" onmouseover="swapImg(this.id,img5.src);" /> Ok, thanks! Link to comment Share on other sites More sharing options...
eduard Posted June 18, 2012 Author Share Posted June 18, 2012 I have to write this function in the head, not in the body? Link to comment Share on other sites More sharing options...
eduard Posted June 18, 2012 Author Share Posted June 18, 2012 What about my css if I write: <script type="text/javascript">? Link to comment Share on other sites More sharing options...
thescientist Posted June 18, 2012 Share Posted June 18, 2012 I don't don't know what that means. I'm not sure what the inclusion of CSS has to do with JS inclusion. If you look at the tutorials they tell you the way you can add JS to your page. Like CSS though, it is recommended that you include it through an external file. Link to comment Share on other sites More sharing options...
eduard Posted June 18, 2012 Author Share Posted June 18, 2012 (edited) I don't don't know what that means. I'm not sure what the inclusion of CSS has to do with JS inclusion. If you look at the tutorials they tell you the way you can add JS to your page. Like CSS though, it is recommended that you include it through an external file. Ok, but when I want the JS function in the head I´ve to write: : <script type="text/javascript"> aswell as : <script type="text/css">? Sorry, I was confused: css is a style; not a script! Edited June 18, 2012 by eduardlid Link to comment Share on other sites More sharing options...
boen_robot Posted June 18, 2012 Share Posted June 18, 2012 Sorry, I was confused: css is a style; not a scriptYes... but you saidWhat about my css if I write: <script type="text/javascript">?And that is what thescientist is correction you about. Seeing that you caught your own error, I'm guessing this was just a typo, correct? Link to comment Share on other sites More sharing options...
eduard Posted June 18, 2012 Author Share Posted June 18, 2012 something like this// imgId is the id of the image you want to change// newSrc is the new image pathfunction swapImg(imgId,newSrc){elm = document.getElementById(imgId);elm.src = newSrc;return true;}//pre load the imagevar img5=new Image();img5.src="myImage.jpg"; // mouse over example<img src="someImage.jpg" onmouseover="swapImg(this.id,img5.src);" /> I´m beginning to understand your reply (I´m now learning JS), but how do I write it in my html file? Link to comment Share on other sites More sharing options...
thescientist Posted June 19, 2012 Share Posted June 19, 2012 read the tutorials. 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