Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    SCRIPT5007: Unable to get property 'top' of undefined or null and too much recursion

    I am not sure about placing two questions into one post, but here it goes:

    The error above "SCRIPT5007: Unable to get property 'top' of undefined or null" is coming from this function:

    Code:
    $(function () { //this is the way to run your code at the DOM Ready event
    
        $('a').click(function () {
            $('html, body').animate({
                scrollTop: $($(this).attr('href')).offset().top
            }, 1500);
            return false;
        });
    
    });
    This is the effected code I believe that is causing the problem:

    Code:
    scrollTop: $($(this).attr('href')).offset().top
    the error occurs when I click on a "clear" button in my form. My website is one long page and that function allows my navigation to slide up and down the site. Without it, everytime you click a nav, it jumps to that anchor.

    For the 2nd problem, the too much recursion, the problem lies within here:

    Code:
    function () {
            if ($.isReady) return;
            imReady = true; $.each($.includeStates,
                        function 
                    (url, state)
                        { if (!state) return imReady = false });
            if (imReady) { $.readyOld.apply($, arguments) }
            else { setTimeout(arguments.callee, 10) }
        }
    where the error is actually coming from the 2nd "function" script. This is part of the browser compatibility script for mozilla/opera at the top of the index page. Any help would be great. Thanks.

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Code:
    scrollTop: $($(this).attr('href')).offset().top
    = $(http://whatever.com).offset().top

    you need

    Code:
    scrollTop:$(this).offset().top

  • Users who have thanked DanInMa for this post:

    colasus (07-23-2013)

  • #3
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    adding this code:

    Code:
    scrollTop:$(this).offset().top
    corrects the button problem as it clears now, but now the scrolling is effected. If I click on a nav link, it goes down 10 px and stops instead of going to the anchor point. So now the code looks like this:

    Code:
    $(function () { //this is the way to run your code at the DOM Ready event
    
        $('a').click(function () {
            $('html, body').animate({
                scrollTop: $(this).offset().top
            }, 1500);
            return false;
        });
    
    });
    I apologize, I didn't know what you were wanting me to do with this code:

    Code:
    = $(http://whatever.com).offset().top

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Ahh. duh sorry. I see what you mean. ok stolen from http://speckyboy.com/2012/03/07/scro...k-with-jquery/

    ( Id advise using a more specific selector than $('a') though. )

    Code:
    function scrollToDiv(element,navheight){
    var offset = element.offset();
    var offsetTop = offset.top;
    var totalScroll = offsetTop-navheight;
    $('body,html').animate({
    scrollTop: totalScroll
    }, 500);
    }
    
    $('a').click(function(){
    var el = $(this).attr('href');
    var elWrapped = $(el);
    scrollToDiv(elWrapped,40);
    return false;
    });

  • Users who have thanked DanInMa for this post:

    colasus (07-24-2013)

  • #5
    New to the CF scene
    Join Date
    Jul 2013
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks for the code and the site! It's always good to have code that works but if you don't understand it, or can't replicate it in the future, it doesn't help as much. The code works great now and I will save that for future reference! I only seem to be good at css right now so if you need any help in that or actual design, let me know!


  •  

    Posting Permissions

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