【问题标题】:How to window.location.hash-change the location, then run a function?如何window.location.hash-改变位置,然后运行一个函数?
【发布时间】:2012-05-17 23:12:55
【问题描述】:

我有一个功能,比如说

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

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

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

【问题讨论】:

  • “之后”是什么意思?在 UI 滚动到那个锚点之后?
  • 是的!在 JQuery Mobile 滚动到那里之后!基本上,在 runSomething 完成之前,我看不到它在做什么!
  • 换句话说,它做了一些事情,我没有看到它,因为它在完成之前不会进入那个部分
  • 他们有,但是已经很晚了,你只给了他们 12 分钟。 This is not 热线 :)
  • #processsection 是一个页面吗?即<div data-role="page" id="processsection">。给我们更多的代码,这样我们就能看到更大的图景。或者,如果您可以制作一个 jsfiddle 来说明问题。

标签: javascript jquery-mobile hashchange


【解决方案1】:

在您的场景中,我可能会使用 if 条件来检查该 div 或 body(以适用者为准)是否正在播放动画。滚动。这是一个未经测试的粗略想法。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-11
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 2015-12-26
    • 2017-03-06
    • 1970-01-01
    • 2020-03-03
    相关资源
    最近更新 更多