开发者

using jQuery address plug in and window.location update without executing address.change twice

开发者 https://www.devze.com 2023-01-18 16:12 出处:网络
I have two events that need to be executed in this order: tabs toggled into/out of view the browser navigating to a hash tag as it would normally (jumping down the page to the anchor)

I have two events that need to be executed in this order:

  1. tabs toggled into/out of view

  2. the browser navigating to a hash tag as it would normally (jumping down the page to the anchor)

And I need it to work with the back button.

I wrote my own function gotoanchor() which accomplishes the first two and because I am navigating to the page using location.href the move is added to the browser history by the browser.

I need jQuery to intercept the back/forward buttons and let me hide/show the tabs before scrolling the page.

The most hopeful looking plug in I've found is jQuery Address

This is my code as it stands:

 $("a[href^=#]")开发者_如何学运维.click(function(){
        gotoanchor(this.hash);
        return false;
});

$.address.externalChange(function(event) {
    // do something depending on the event.value property, e.g.
    gotoanchor(event.value);
});

I'm having 3 problems:

  1. the location.href update is considered an externalChange by address and it executes the code in response to it. I can't just let address manage the history because it doesn't scroll down the page to where the hash is.

  2. address wants to update the hash on it's own too. The API is quite extensive and I'm reasonably sure there's a way to tell it not to but the documentation could use some work.

  3. it's adding #/#hash to my URL and I'd rather it was just #hash

Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消