如何window.location.hash-更改位置,然后运行一个函数?

时间:2012-05-17 23:12:56

标签: javascript jquery-mobile hashchange

我有一个功能,比如说

function runSomething()
{
   alert("hello");
}

我有window.onhashchange = runSomething;
在我的代码中,我致电window.location.hash = "#processsection"

runSomething运行,但它在页面执行到#processsection之前运行...我怎么才能让它只在我运行#processsection之后运行?

1 个答案:

答案 0 :(得分:0)

在你的场景中,我可能会使用if条件来检查div或body(无论哪个适用)是否为动画。滚动。这是一个未经考验的粗略想法。

function runSomething() {        
    if ($('body').is(':animated') {
        $('body').queue(function() {
            alert("hello");
        });
    } else {
        alert("hello");
    }
}