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

here you will find only solved Help topics

Moderator: 1.2 Moderators

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

Postby jrealist1 on Wed Feb 24, 2010 4:53 am

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.  
jrealist1
 
Posts: 12
Joined: Thu Nov 19, 2009 11:31 pm

Re: Changing font color (not background) on rollover

Postby wowenkho on Wed Feb 24, 2010 5:27 am

  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. });
my sword is yours...
http://wowenkho.com

for those who want to talk with me quicker, add me on Yahoo! Messenger through my ID: michaelapeles
User avatar
wowenkho
mootools freak
 
Posts: 1146
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines

Re: Changing font color (not background) on rollover

Postby jrealist1 on Thu Feb 25, 2010 5:57 am

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-->
jrealist1
 
Posts: 12
Joined: Thu Nov 19, 2009 11:31 pm

Re: Changing font color (not background) on rollover

Postby wowenkho on Thu Feb 25, 2010 6:53 am

well, if that's the case, the code should work... anyway here: http://mootools.net/shell/wZ7Pu/
my sword is yours...
http://wowenkho.com

for those who want to talk with me quicker, add me on Yahoo! Messenger through my ID: michaelapeles
User avatar
wowenkho
mootools freak
 
Posts: 1146
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines

Re: Changing font color (not background) on rollover

Postby jrealist1 on Thu Feb 25, 2010 6:04 pm

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.
jrealist1
 
Posts: 12
Joined: Thu Nov 19, 2009 11:31 pm

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

Postby jrealist1 on Fri Feb 26, 2010 5:28 am

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?
jrealist1
 
Posts: 12
Joined: Thu Nov 19, 2009 11:31 pm

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

Postby wowenkho on Fri Feb 26, 2010 8:55 am

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.
my sword is yours...
http://wowenkho.com

for those who want to talk with me quicker, add me on Yahoo! Messenger through my ID: michaelapeles
User avatar
wowenkho
mootools freak
 
Posts: 1146
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines

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

Postby jrealist1 on Fri Feb 26, 2010 4:27 pm

exactly... so I'm going to have to use CSS. *sigh*
Thanks
jrealist1
 
Posts: 12
Joined: Thu Nov 19, 2009 11:31 pm

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

Postby wowenkho on Sat Feb 27, 2010 2:45 am

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.
my sword is yours...
http://wowenkho.com

for those who want to talk with me quicker, add me on Yahoo! Messenger through my ID: michaelapeles
User avatar
wowenkho
mootools freak
 
Posts: 1146
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines


Return to Solutions

Who is online

Users browsing this forum: No registered users and 2 guests