SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict rabbitdog's Avatar
    Join Date
    Jul 2001
    Location
    So. Tenn.
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick help on two conflicting jquery snippets

    Hi all, I'm still at cut 'n paste proficiency level with javascript, so when I'm unsure how to resolve this conflict I'm having between two scripts. Hoping someone can help.

    I have one script which has a lovely effect of fading all the pages on my site in and out:

    Code JavaScript:
    <script type="text/javascript">
    $(document).ready(function() {
        $("body").css("display", "none");
     
        $("body").fadeIn(1000);
     
        $("a").click(function(event){
            event.preventDefault();
            linkLocation = this.href;
            $("body").fadeOut(500, redirectPage);
        });
     
        function redirectPage() {
            window.location = linkLocation;
        }
    });
    </script>

    In addition, I'm integrating the default accordion effect from jquery: http://jqueryui.com/demos/accordion/

    The problem I'm having is that I need the links for the accordion (which just link to #) NOT to activate the fade script.

    Because it makes things go explode-y when I do.

    It seems like I should be able to apply a class to the links I DON'T want to activate the fade and then toss in an if statement in the above code, but I'm not sure how to do that.

    Any help would be greatly appreciated!
    Mr Vector
    High quality, royalty free, vector graphics
    for t-shirt artists and graphic/web designers.

  2. #2
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't need a class. Check if the href is equal to '#'. If so, then do nothing, else redirect the page. Tada ! problem solved .

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by rabbitdog View Post
    The accordion already sets a class on to the parent of those accordion links, so you can check for that at the start of the click function, and return out if it's found.
    Code javascript:
    if (this.parent().hasClass('ui-accordion-header')) {
        return;
    }
    Last edited by paul_wilkins; Jan 24, 2011 at 20:52.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Addict rabbitdog's Avatar
    Join Date
    Jul 2001
    Location
    So. Tenn.
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome. Thanks so much! Worked like a champ.
    Mr Vector
    High quality, royalty free, vector graphics
    for t-shirt artists and graphic/web designers.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •