SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help excluding "#div" from a function, is this possible!

    Hello, I am having a problem trying to exclude some "#divs" from a scrolling function.

    The problem I have is that I use a scrolling script that slides the page vertically to some defined div "#anchors"

    But I am trying to build some sliding tabs as well, the problem is that when clicking the tabs I am triggering the "scroll page" script instead of the tabs sliding script, so I am wondering if I can exclude the tabs menu "#divs" from the scroll page script so that there is no conflict. Please let me know if this is possible, is very important for me, thanks!

    here is the scrolling script:

    $(document).ready(function(){

    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')

    && location.hostname == this.hostname) {
    var $target = $(this.hash);
    $target = $target.length && $target
    || $('[name=' + this.hash.slice(1) +']');
    if ($target.length) {
    var targetOffset = $target.offset().top;
    $('html,body')
    .animate({scrollTop: targetOffset}, 1000);
    return false;
    }
    }

    });


    });


    And here is what I tried doing, but it is not working:

    $(document).ready(function(){


    $("#first").click(function() {
    window.onbeforeunload = null;
    });

    $("#second").click(function() {
    window.onbeforeunload = null;
    });

    $("#third").click(function() {
    window.onbeforeunload = null;
    });

    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')

    && location.hostname == this.hostname) {
    var $target = $(this.hash);
    $target = $target.length && $target
    || $('[name=' + this.hash.slice(1) +']');
    if ($target.length) {
    var targetOffset = $target.offset().top;
    $('html,body')
    .animate({scrollTop: targetOffset}, 1000);
    return false;
    }
    }




    });


    });

  2. #2
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi I found a way to make it work, actually the problem is that the "#" in the main function is generic so it affects all the divs in the page, I fixed it by using
    #name1, #name2 (for the scrolling anchors, that way it only affects those ones and not the #anchors of the sliding tabs)

    My question is simple, sorry I am a bit of a noob in javascript

    I want to put several divs in this function (right now I am just repeating the function and changing div names, but this is not so skillful.

    ex...
    $('a[href*=#div1]').click(function() {....

    $('a[href*=#div2]').click(function() {.....

    $('a[href*=#div3]').click(function() {....


    how do I put "div1,div2 and #div3 on the same function, I tried:

    $('a[href*=#div1,#div2,#div3]').click(function() {....

    but is not working, any clues? Thanks a lot!

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    $('a[href*=#div1],a[href*=#div2],a[href*=#div3]').click(function() {....

    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey ScallioXTX!

    Thanks a lot that works awesome!!, I do appreciate your help!

    -Manuel


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
  •