www.webdeveloper.com
Results 1 to 7 of 7

Thread: Scroll to the top - can't make it work

  1. #1
    Join Date
    Nov 2013
    Posts
    4

    Question Scroll to the top - can't make it work

    Hi,

    There is a little bit of javascript in a template form that is no longer working and I'm thinking that someone who knows what they are doing will be able to see the error and help me out.

    Here's the code snippet:


    /////////////////* Go to top link */////////////////////////

    $("#main").find('#top').on("click", function () {
    "use strict";
    var bdy = $('#main');
    bdy.animate({ scrollTop: 0 }, 'slow');
    });

    You can see it *not* working here - http://theautospakingston.ca/index.html.

    Where you see the word '#main', the original author had '#right', b/c there use to be a div called 'right'. That div is now gone, so I thought that changing 'right' to 'main' (which is the name of the div that is there) would work.

    Any help with this would be appreciated. Thx.

  2. #2
    Join Date
    Nov 2013
    Posts
    4
    I have tried a few different solutions, but couldn't get it to work, so I have defaulted back to a more simple link to the top.

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,637
    Code:
    $('#top').click(function(){
    $('html,body').animate({scrollTop:0},'slow');
    });
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  4. #4
    Join Date
    Nov 2013
    Posts
    4
    Thanks for this. I inserted this to see if it would work and it didn't. I had tried something quite similiar. I'm not sure what is up, but I am not going to stress about this particular site, since combing through the code is not worth it for the return at this point.

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,637
    in 99% i test every code before posting. this code worked with your site (with all the other scripts excepting jquery commented, see the demo page source). look for possible errors/conflicts in the commented scripts

    live demo
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  6. #6
    Join Date
    Nov 2013
    Posts
    4
    Thank you! That is awesome! I really appreciate your help.

  7. #7
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,637
    anytime ))
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles