Page 1 of 1

[solved] Changing font color (not background) on rollover

PostPosted: Wed Feb 24, 2010 4:53 am
by jrealist1
I am trying to change the font color on rollover for a navigation I am put together with mootools. I know how to change the background color but how do you change the font color?

I don't want to list my navigation.

Here is what I have:
  1.  
  2. window.addEvent('domready', function(){
  3.        //select all a element from your page
  4.     var list = $$('#Nav_wrapper .typeface-js');
  5.     list.each(function(element) {
  6.     // We change the default 'link' property to 'cancel' for the morph effect,
  7.     // this will ensures effects are interrupted when the mouse is leaving
  8.     // and entering, so the morph effect being called begin immediately
  9.     element.set('morph', {link : 'cancel'});
  10.     oldcolor=element.getStyle('#122c3c');
  11.    // on mouse enter on our element we put in oldcolor the current color
  12.    // and we morph to #aaa the result is a fading effect from the font color to #aaa
  13.    // (you can use morph with any css property)
  14.     element.addEvent('mouseenter', function(){
  15.         element.morph({
  16.             'color': '#b53832'
  17.         });
  18.     });
  19.    // on mouse leave on our element we morph back to oldcolor
  20.   // the result is a fading effect on font color from #aaa to oldcolor
  21.     element.addEvent('mouseleave', function(){
  22.         element.morph({
  23.             'color': oldcolor,
  24.         });
  25.     });
  26.     });
  27.  
  28. });
  29.  

Re: Changing font color (not background) on rollover

PostPosted: Wed Feb 24, 2010 5:27 am
by wowenkho
  1. window.addEvent('domready', function(){
  2.        //select all a element from your page
  3.     var list = $$('#Nav_wrapper .typeface-js');
  4.     list.each(function(element) {
  5.     // We change the default 'link' property to 'cancel' for the morph effect,
  6.     // this will ensures effects are interrupted when the mouse is leaving
  7.     // and entering, so the morph effect being called begin immediately
  8.     element.set('morph', {link : 'cancel'});
  9.     var oldcolor = element.getStyle('color');
  10.    // on mouse enter on our element we put in oldcolor the current color
  11.    // and we morph to #aaa the result is a fading effect from the font color to #aaa
  12.    // (you can use morph with any css property)
  13.     element.addEvent('mouseenter', function(){
  14.         element.morph({
  15.             'color': '#b53832'
  16.         });
  17.     });
  18.    // on mouse leave on our element we morph back to oldcolor
  19.   // the result is a fading effect on font color from #aaa to oldcolor
  20.     element.addEvent('mouseleave', function(){
  21.         element.morph({
  22.             'color': oldcolor
  23.         });
  24.     });
  25.   });
  26. });

Re: Changing font color (not background) on rollover

PostPosted: Thu Feb 25, 2010 5:57 am
by jrealist1
Hi wowenkho,

Thank you for your suggestion. The Javascript is still now working properly. I forgot to include the HTML in my previous post.
In order to change the background color on mouse enter I would use "backgroundColor" what would i use to change the font color on mouse enter "color" or "font-color" or neither?
  1.  
  2. <!--- begin nav wrapper -->
  3. <div id="Nav_wrapper">
  4.                 <a href="#" class="typeface-js" title="Begin">Begin</a>
  5.                 <a href="#" class="typeface-js" title="Portfolio">Portfolio</a>
  6.                 <a href="#" class="typeface-js" title="About">About</a>
  7.                 <a href="#" class="typeface-js" title="Blog">Blog</a>
  8.                 <a href="#" class="typeface-js" title="Contact">Contact</a>                
  9. </div><!--end nav wrapper-->

Re: Changing font color (not background) on rollover

PostPosted: Thu Feb 25, 2010 6:53 am
by wowenkho
well, if that's the case, the code should work... anyway here: http://mootools.net/shell/wZ7Pu/

Re: Changing font color (not background) on rollover

PostPosted: Thu Feb 25, 2010 6:04 pm
by jrealist1
Hi wowenkho,

The code does seem to be working in mooShell... obviously I am doing something wrong and will take another shot at it.

Thanks for your help.

Re: [solved] Changing font color (not background) on rollover

PostPosted: Fri Feb 26, 2010 5:28 am
by jrealist1
wowenkho,

I believe the reason the mouseenter and mouseleave effect is not working properly for me is because I am using typeface.js to embed a custom font face with out using an image ( http://typeface.neocracy.org/) This is just my theory... Is there a working around this problem with mootools or will I have to result in using a CSS hover?

Re: [solved] Changing font color (not background) on rollover

PostPosted: Fri Feb 26, 2010 8:55 am
by wowenkho
ah no wonder. because of typeface.js or cufon.js, it would be hard to manipulate it by using the "color" property since we're dealing with canvas or svg or flash or whatever was replaced with the simple text.

Re: [solved] Changing font color (not background) on rollover

PostPosted: Fri Feb 26, 2010 4:27 pm
by jrealist1
exactly... so I'm going to have to use CSS. *sigh*
Thanks

Re: [solved] Changing font color (not background) on rollover

PostPosted: Sat Feb 27, 2010 2:45 am
by wowenkho
css in itself might not even help in this matter either, if you're not aware what CSS properties to use. but as a general rule, if you're going to use text replacement stuff, better get prepared in not changing its appearance just as easily as when dealing with simple text.