views:

205

answers:

2

i want a certain DOM element to fade into view in my script. i tried using the timeout feature but couldnt get it to work.

hover.addEventListener('mouseover',function () {Core.addClass(cpanel,"on");},false);

please tell me how to implement a fade-in effect for this. please dont recommend jquery or any other framework.

+5  A: 

Can you provide markup to go with your JS, so we know what we're looking at?

Also, if you don't want to use jQuery or another framework, you can still look at their implementations to see how to make this kind of thing work. Fading is a notoriously difficult thing to implement cross-browser because of IE6's spotty transparency support.

DDaviesBrackett
+1: Looking at other implementations is the best way to learn how to do it.
musicfreak
A beginner probably won't be able to pick up anything from massive libraries like jQuery.
J-P
the cpanel is a particular div that i would like to fade into view.
amit
What's Core, then? and you haven't said why you don't want jQuery.
DDaviesBrackett
the Core is a library im using. and the reason i dont want to use jquery is that i dont know jquery at all.
amit
It will be FAR quicker to 'learn' jQuery than to reimplement it. Really, if you know CSS selectors and how to read API documents, you're more than halfway there.
Jeff
+1  A: 

So many excellent Javascript developers have written animation functions, you'd really do yourself a favor (and your viewers) to use theirs. People are suggesting jQuery, which is great. MooTools is another great alternative.

However, if you want a nudge in a direction of how to write animation in Javascript, I cooked something up here real fast. Note that there's been no cross-browser testing, I'm sure it doesn't work in IE6 (IE7 even?). Nor would I want to, I appreciate the code others have already tested for me.

This is just an idea of how you could do so with native Javascript:

function fadeIn(el, speed) {
    el.style.opacity = 0;
    var interval = setInterval(function(){
     el.style.opacity = parseFloat(el.style.opacity) + 0.1;
     if(el.style.opacity == 1.0) {
      clearInterval(interval);
     }
    },speed / 10);
}
seanmonstar
if i do try to use jquery, can i write the jquery code inside my javscript file or do i need to make another file for the jquery code?
amit
if you use jquery, all you need to do is include jQuery before you're own Javascript file in the html. then you can write all you want with jquery.
seanmonstar