views:

37

answers:

2

I am trying to animate my navigation menu with jQuery Link Fading effect. I got the script from David Walsh Blog.

I've put 3 test links right above my main navigation menu. It works fine, just as I expected it to. But when I add the class="fade" to the <ul id="topmenu" class="fade"> like so:

<script type="text/javascript" src="jquery.dwFadingLinks.js"></script> 
<script type="text/javascript" src="jquery.effects.core.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() {
        $('.fade').dwFadingLinks({
            color: '#000',
            duration: 300
        });
     });
</script>


<body>
<div id="wrapper">
    <div id="header">
        <div id="top">
            <ul id="topmenu" class="fade">
                <li id="conor"><a href="/">Sahat Yalkabov</a></li>
                <li><?php pages(); ?></li>
            </ul>
    </div>

    <div id="content">
        <div id="main">
            <?php center(); ?>
        </div>

    </div>
    <div id="footer">
        <p>Copyright &copy; 2010 Sahat Yalkabov [ <?php login_link(); ?> ]
        </p>
    </div>
</div>
</body>
</html>

It has no effect at all. Still normal CSS hover.

I have even tried adding class="fade" to every element in the body, still nothing.

EDIT: The navigation links are PHP-generated as you can see I am calling links from <li><?php pages(); ?></li>

UPDATE: Thank you MvanGeest. Your solution has solved my problem :).

+2  A: 

I think I have the answer:

In the javascript change:

$(document).ready(function() {
    $('.fade').dwFadingLinks({
        color: '#000',
        duration: 300
    });
});

to

$(document).ready(function() {
    $('a.fade').dwFadingLinks({
        color: '#000',
        duration: 300
    });
});

and then put class="fade" onto the acctual links. :) I did this in firebug and it seems to work.

Thomas Clayson
You can also use `$('.fade a')` without changing the HTML.
MvanGeest
My links are not hard-coded. Should I put the class="fade" in <ul id="topmenu" class="fade"> like that? Or inside of <li> like so: <li class="fade"><?php pages(); ?></li>
Silence of 2012
Thank you MvanGeest! It worked! /bow
Silence of 2012
how are they generated? can you not change where they are generated? or use something like below: $('div#header a')MvanGeest - thnks for changing my answer - I couldn't get it add in the line breaks! :( plus how do you get inline code in the comments?
Thomas Clayson
They are generated through php. I am using sNews platform. No idea how exactly it generates links. Inline code in comments? I don't know if it's possible. Never seen it myself at least.
Silence of 2012
have you tried the other selector? $('div#header a') ?? did that work?
Thomas Clayson
+2  A: 

The links your generating, those that aren't fading don't have the class attribute with class .fade set.

Why don't you try something like:

$(document).ready(function() {
    $('div#header a').dwFadingLinks({
        color: '#000',
        duration: 300
    });
});

Makes sense, because all the links in the header should fade anyways--no need to set the class attribute.

kRON
That would probably work. But this worked too $('.fade a') so I'll just use that :). Thanks kRON!
Silence of 2012