Pawan_Agarwal Posted July 18, 2013 Share Posted July 18, 2013 I am trying to code something in Java-script, I am trying to "fade_in" image and "fade_out" image with Set_interval function, I am facing problem, help me @@@@@ <html> <script type="text/javascript"> var inc_bit =1e-2; function inc_change() { var s = document.getElementById('img'); document.getElementById('write').innerHTML = inc_bit; inc_bit = inc_bit + 1e-2; s.style.opacity = inc_bit; if(inc_bit>1e0) { setInterval(function() {dec_change();},100); } } function dec_change() { var s = document.getElementById('img'); document.getElementById('write').innerHTML = inc_bit; inc_bit = inc_bit - 1e-2; s.style.opacity = inc_bit; if(inc_bit<1e-2) { setInterval(function() {inc_change();},100); } } setInterval(function() {inc_change();},90); </script> <body onload="inc_change()"> <img src="pic1.jpg" height="200px" width="250px" id="img" style="opacity:0.0"/> <div id='write'></div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/280270-appear-image-and-disappear-image/ Share on other sites More sharing options...
cyberRobot Posted July 18, 2013 Share Posted July 18, 2013 It might help to have a description of the problem. What is it doing that you don't expect? Link to comment https://forums.phpfreaks.com/topic/280270-appear-image-and-disappear-image/#findComment-1441232 Share on other sites More sharing options...
Pawan_Agarwal Posted July 18, 2013 Author Share Posted July 18, 2013 It gets turn into infinite loop and browser execution terminates, I am trying to perform a simple code Just understand that I have a variable age and it gets incremented by one function called z1() now when age gets 18 it must call 2nd function called z2() that must start decreasing the age.............I think I am clear what I am trying to perform in the above code.......age is starting from 1 to 18 and then decreasing from 18 to 1 and this has to be achieved infinitely....... I am trying to increase and decease the opacity of image with time and I am facing some issue while handling the code.......... Link to comment https://forums.phpfreaks.com/topic/280270-appear-image-and-disappear-image/#findComment-1441251 Share on other sites More sharing options...
cyberRobot Posted July 18, 2013 Share Posted July 18, 2013 Have you looked into clearInterval()? https://developer.mozilla.org/en-US/docs/Web/API/window.clearInterval Link to comment https://forums.phpfreaks.com/topic/280270-appear-image-and-disappear-image/#findComment-1441272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.