conan318 Posted July 27, 2012 Share Posted July 27, 2012 the div fades in and out once but if i press the button again it wont fade div a second time... <script type="text/javascript"> var fadeEffect=function(){ return{ init:function(id, flag, target){ this.elem = document.getElementById(id); clearInterval(this.elem.si); this.target = target ? target : flag ? 100 : 0; this.flag = flag || -1; this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0; this.si = setInterval(function(){fadeEffect.tween()}, 50); }, tween:function(){ if(this.alpha == this.target){ clearInterval(this.si); }else{ var value = Math.round(this.alpha + ((this.target - this.alpha) * .01)) + (1 * this.flag); this.elem.style.opacity = value / 100; this.elem.style.filter = 'alpha(opacity=' + value + ')'; this.alpha = value } } } }(); </script> Link to comment https://forums.phpfreaks.com/topic/266318-fading-div-in-and-out/ Share on other sites More sharing options...
gristoi Posted July 27, 2012 Share Posted July 27, 2012 why not just use jquery? $('#id_of_element').fadeOut(); etc Link to comment https://forums.phpfreaks.com/topic/266318-fading-div-in-and-out/#findComment-1364831 Share on other sites More sharing options...
conan318 Posted July 27, 2012 Author Share Posted July 27, 2012 i have never used jquery b4.. do I need to download a library to use it? Link to comment https://forums.phpfreaks.com/topic/266318-fading-div-in-and-out/#findComment-1364855 Share on other sites More sharing options...
conan318 Posted July 27, 2012 Author Share Posted July 27, 2012 cheers jquey has solved my issue Link to comment https://forums.phpfreaks.com/topic/266318-fading-div-in-and-out/#findComment-1364864 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.