防止在散列更改或单击时向下滚动

时间:2012-12-18 18:00:11

标签: javascript jquery hash scroll

  

可能重复:
  Modifying document.location.hash without page scrolling

如何在哈希发生变化时阻止页面向下滚动到主题标签?我尝试了以下方法:

$("#button_bar a").click(function(event) {
    event.preventDefault(); //This was to prevent the hash scroll down behavior

    window.location.hash = this.hash; //This makes scroll down to the hash again

    $(window).hashchange( function(){ //this recognizes if the hash has changed
        recognizeHashTag();  //this identifies the hashtag and fires an ajax call
    });
});

问题是当我引用window.location.hash = this.hash时,它什么也没做。当它没有引用时,哈希行为再次出现。 如果有人有一个想法,非常感谢。

0 个答案:

没有答案