Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:15:15+00:00 2026-06-14T17:15:15+00:00

I use a position:fixed menu at http://communitychessclub.com/index.php to keep the menu on screen even

  • 0

I use a position:fixed menu at http://communitychessclub.com/index.php to keep the menu on screen even as the user scrolls:

CSS:

#sticky {margin:0 auto; display:table}
#sticky.stick {position: fixed;  top: 0; margin-left:48px; z-index: 10000; }

JS:

<script>
function sticky_relocate() {
    var window_top = $(window).scrollTop();
    var div_top = $('#sticky-anchor').offset().top;
    if (window_top > div_top)
        $('#sticky').addClass('stick')
    else
        $('#sticky').removeClass('stick');
}

$(function() {
    $(window).scroll(sticky_relocate);
    sticky_relocate();
});

$(window).scroll((function() {
    var a='',  // a buffer to the hash
    w = $(window);
    return function() {
        var h = location.hash;
        // if hash is different from the previous one, which indicates
        // the hash changed by user, then scroll the window down
        // update the buffer
        if (h != a) {            
            a = h;           
            w.scrollTop(w.scrollTop()-150)
        }
    };
})());
</script>

But people complain that to link to an ID on the same page causes the screen to abruptly scroll. So I found “Improving User Experience With jQuery Smooth Page Anchor Transitions” at http://www.spydertrap.com/blog/2012/08/user-experience-jquery-smooth-page-anchor-transitions/ and liked the demo. Liked it so much that I want to blend the jquery code below with the jquery code above for a smooth jquery scroll.

They use this (but other versions exist here… problem is how to join the two)

jQuery Code:

function goToByScroll(id){
    $('html,body').animate({scrollTop: $(id).offset().top},'slow');
}

HTML:

<ul class="nav">
    <li><a href="#chapter1">Chapter 1</a></li>
    <li><a href="#chapter2">Chapter 2</a></li>
    <li><a href="#chapter3">Chapter 3</a></li>
</ul>

JS launcher:

$(document).ready(function(){
    $('.nav a').click(function(){
        goToByScroll($(this).attr('href'));
        return false;
    });
});

Is this possible to unite with the jquery code above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:15:16+00:00Added an answer on June 14, 2026 at 5:15 pm

    I just tried this by hacking on your page through the chrome browser’s JS console. I added the function goToByScroll verbatim and then executed this:

    $('#sticky a').click(function(){
        goToByScroll($(this).attr('href'));
        return false;
    });
    

    And sure enough, it scrolls between anchor IDs. There is a minor problem of an exception being thrown when you click on links in your nav bar that aren’t actual anchor links (e.g. ‘Home’ points to the home page, and ‘Chess Camp’ opens a popup). So you could add a class to the anchor links that you want to have scrolling and then add that class to the selector.

    For example, modify your markup for the sticky menu bar to look like this:

    <li><a href="http://www.chessset.com/">Chess Center</a>
        <div><ul>
    
            <li><a class="anchor" href="#cc_events">about the RCC</a></li>
    
            <li><a href="#" onclick="TINY.box.show({url:'RCC_chess_lessons.php',boxid:'RCC_chess_camp', width:950, height:650}); return false;">chess camp</a></li>
    
            <li><a href="#" onclick="TINY.box.show({url:'RCC_Marchand_Open.php',boxid:'RCC_marchand', width:1000,height:600}); return false;">Marchand Open</a></li>
    
            <li><a href="#" onclick="TINY.box.show({url:'RCC_weekly_schedule.php', boxid:'RCC_schedule', width:775, height:600}); return false;">weekly schedule</a></li>
    
            <li><a class="anchor" href="#picnic">annual picnic</a></li>
    
            <li><a href="http://www.chessset.com/">Chess gear sale</a></li>
    
        </ul></div>
    </li>
    

    (added class="anchor" to all the links that pointing to a hash on the same page.)

    And add this to your javascript:

    // sticky_relocate function here
    
    // Add this function exactly from your example
    function goToByScroll(id){
        $('html,body').animate({scrollTop: $(id).offset().top},'slow');
    }
    
    // modify your onReady jQuery handler to this:
    $(function() {
        $(window).scroll(sticky_relocate);
        sticky_relocate();
    
        // Added the .anchor to the selector
        $('#sticky a.anchor').click(function(){
            goToByScroll($(this).attr('href'));
            return false;
        });
    });
    
    // your $(window).scroll goes here
    

    That should work for you without throwing any errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site that utilizes a bottom fixed position masthead here: http://www.entheospartners.com/newsite/ This
Just found the link with a visible element with position:fixed behaves kinda strange: http://www.steadyhealth.com/Do_you_need_to_use_a_back_up_method_for_the_first_week_of_every_month_while_on_birth_control__t267326.html
How do I use the CSS background-position property to center a background image to
You know when you use the CSS background-position property for rollovers, right? Roll over
trying to learn some html/css and I'm having a problem with fixed position divs.
suppose i have css like position: fixed; width: 200px; height: 100px; top: 50%; left:
I am having problem with margin-top in ie7 if i use position fixed in
I have a few div boxes that are using position:fixed and I use a
here is a standard use of float and fixed : <html> <head> <style type=text/css>
I use position:fixed for creating a chat window like gmail it works correclty in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.