Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top bar anchors problem #9

Open
jakubsuchybio opened this issue Feb 4, 2015 · 3 comments
Open

Top bar anchors problem #9

jakubsuchybio opened this issue Feb 4, 2015 · 3 comments
Assignees

Comments

@jakubsuchybio
Copy link

When i click on any forum anchor link, then the top edge of rendered page is behind the top bar of pbtech. Could every anchor link be rendered with top edge down under the top bar? So in other words every anchor rendered page moved down by top bar height?
Thank you. Biosek

@PayBas
Copy link
Owner

PayBas commented Feb 4, 2015

You could try inserting some code here: https://github.com/PayBas/style-PBTech/blob/master/pbtech/template/overall_footer.html#L52

    /* Anchor jump offset for top-bar */
    function scroll_if_anchor(href) {
        href = typeof(href) == "string" ? href : $(this).attr("href");

        if(!href) return;
        var fromTop = $topBarHeight + 4;
        var $target = $(href);

        // Older browsers without pushState might flicker here, as they momentarily jump to the wrong position (IE < 10)
        if($target.length) {
            $('html, body').scrollTop($target.offset().top - fromTop);
            if(history && "pushState" in history) {
                history.pushState({}, document.title, window.location.href.split("#")[0] + href);
                //window.location.hash = href;
                return false;
            }
        }
    }

    var $topBar = $('#top-bar');
    var $topBarHeight = 0;

    if ($topBar.length) {
        $topBarHeight = $topBar.outerHeight();

        $("body").on("click", "a[href^='#']", scroll_if_anchor);

        scroll_if_anchor(window.location.hash);
    }

@PayBas PayBas self-assigned this Feb 4, 2015
@jakubsuchybio
Copy link
Author

Works like a charm :). Thank you. Would you consider incorporating this into your next version as well?

@PayBas
Copy link
Owner

PayBas commented Feb 5, 2015

Not sure yet. Requires more testing first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants