动画扩展器问题

发布于 2024-07-05 01:23:32 字数 1089 浏览 9 评论 0原文

我刚刚开始使用 AnimationExtender。 我用它来显示一个新的 div,其中包含按下按钮时从数据库收集的列表。 问题是按钮需要进行回发才能获取此列表,因为除非需要,否则我不想调用数据库。 然而,回发会停止动画并重置它。 该按钮位于更新面板内。

理想情况下,我希望动画在回发完成并且列表已收集后立即开始。 我研究过使用 ScriptManager 来检测回发何时完成并取得了一些进展。 我在页面中添加了两个 javascript 方法。

function linkPostback() {

        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(playAnimation)
    }

    function playAnimation() {
        var onclkBehavior = $find("ctl00_btnOpenList").get_OnClickBehavior().get_animation();
        onclkBehavior.play();
    }

我已经更改了 btnOpenList.OnClientClick=”linkPostback();”

这几乎解决了问题。 我的动画仍然有些卡顿。 动画在回发之前开始播放,然后在回发后正常播放。 使用 onclkBehavior.pause() 没有任何效果。 我可以通过设置 AnimationExtender.Enabled = false 并在按钮回发事件中将其设置为 true 来解决此问题。 然而,这只有效一次,因为现在 AnimationExtender 再次启用。 我还尝试通过 javascript 禁用 AnimationExtender 但这没有效果。

有没有一种方法可以仅通过 javascript 调用来播放动画? 我需要将自动链接解耦到 按钮单击事件,以便我可以控制动画何时触发。

希望这是有道理的。

谢谢

总干事

I have just started working with the AnimationExtender. I am using it to show a new div with a list gathered from a database when a button is pressed. The problem is the button needs to do a postback to get this list as I don't want to make the call to the database unless it's needed. The postback however stops the animation mid flow and resets it. The button is within an update panel.

Ideally I would want the animation to start once the postback is complete and the list has been gathered. I have looked into using the ScriptManager to detect when the postback is complete and have made some progress. I have added two javascript methods to the page.

function linkPostback() {

        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(playAnimation)
    }

    function playAnimation() {
        var onclkBehavior = $find("ctl00_btnOpenList").get_OnClickBehavior().get_animation();
        onclkBehavior.play();
    }

And I’ve changed the btnOpenList.OnClientClick=”linkPostback();”

This almost solves the problem. I’m still get some animation stutter. The animation starts to play before the postback and then plays properly after postback. Using the onclkBehavior.pause() has no effect. I can get around this by setting the AnimationExtender.Enabled = false and setting it to true in the buttons postback event. This however works only once as now the AnimationExtender is enabled again. I have also tried disabling the AnimationExtender via javascript but this has no effect.

Is there a way of playing the animations only via javascript calls? I need to decouple the automatic link to the
buttons click event so I can control when the animation is fired.

Hope that makes sense.

Thanks

DG

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青萝楚歌 2024-07-12 01:23:32

在给出的答案的帮助下,最终解决方案如下:

添加另一个按钮并将其隐藏。

<input id="btnHdn" runat="server" type="button" value="button" style="display:none;" />

将 AnimationExtender 指向隐藏按钮,这样就不会触发不需要的单击事件。

<cc1:AnimationExtender ID="aniExt" runat="server" TargetControlID="btnHdn">

将 javascript 连接到您想要在回发完成后触发动画的按钮。

<asp:ImageButton ID="btnShowList" runat="server" OnClick="btnShowList_Click" OnClientClick="linkPostback();" />

将所需的 Javascript 添加到页面。

function linkPostback() {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(playOpenAnimation)
}

function playOpenAnimation() {
    var onclkBehavior = ind("ctl00_aniExt").get_OnClickBehavior().get_animation();
    onclkBehavior.play();         

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.remove_endRequest(playOpenAnimation) 
}

With help from the answer given the final solution was as follows:

Add another button and hide it.

<input id="btnHdn" runat="server" type="button" value="button" style="display:none;" />

Point the AnimationExtender to the hidden button so the firing of the unwanted click event never happens.

<cc1:AnimationExtender ID="aniExt" runat="server" TargetControlID="btnHdn">

Wire the javascript to the button you want to trigger the animation after the postback is complete.

<asp:ImageButton ID="btnShowList" runat="server" OnClick="btnShowList_Click" OnClientClick="linkPostback();" />

Add the required Javascript to the page.

function linkPostback() {
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_endRequest(playOpenAnimation)
}

function playOpenAnimation() {
    var onclkBehavior = ind("ctl00_aniExt").get_OnClickBehavior().get_animation();
    onclkBehavior.play();         

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.remove_endRequest(playOpenAnimation) 
}
北方的韩爷 2024-07-12 01:23:32

您看到的流程是这样的:

  1. 单击按钮
  2. AnimationExtender 捕获操作并调用 clickOn 回调
  3. linkPostback 启动页面的异步请求,然后将流程返回给 AnimationExtender
  4. 动画开始
  5. pageRequest 返回并调用 playAnimation,这会再次启动动画

我认为有至少有两种方法可以解决这个问题。 看来您几乎拥有所需的所有 JavaScript,您只需要解决 AnimationExtender 即可通过单击启动动画。

选项 1:隐藏 AnimationExtender 按钮并添加您自己的用于播放动画的新按钮。 这应该像将 AE 按钮的样式设置为“display: none;”一样简单 并让您自己的按钮调用 linkPostback()。

选项 2:动画完成后重新禁用动画扩展器。 只要 playAnimation 调用被阻塞,这应该有效,这可能是:

function linkPostback() {

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(playAnimation)
}

function playAnimation() {

    AnimationExtender.Enabled = true;
    var onclkBehavior = $find("ctl00_btnOpenList").get_OnClickBehavior().get_animation();
    onclkBehavior.play();
    AnimationExtender.Enabled = false;
}

顺便说一句,如果接收 pageRequest 出现延迟,您的一般方法似乎可能会遇到问题。 单击按钮并在几秒钟后发生动画可能有点奇怪。 最好预先加载数据,或者在 div 中预先填充一些“正在加载...”的内容,使其大小合适,然后在实际内容到达时填充它。

The flow you are seeing is something like this:

  1. Click on button
  2. AnimationExtender catches action and call clickOn callback
  3. linkPostback starts asynchronous request for page and then returns flow to AnimationExtender
  4. Animation begins
  5. pageRequest returns and calls playAnimation, which starts the animation again

I think there are at least two ways around this issue. It seems you have almost all the javascript you need, you just need to work around AnimationExtender starting the animation on a click.

Option 1: Hide the AnimationExtender button and add a new button of your own that plays the animation. This should be as simple as setting the AE button's style to "display: none;" and having your own button call linkPostback().

Option 2: Re-disable the Animation Extender once the animation has finished with. This should work, as long as the playAnimation call is blocking, which it probably is:

function linkPostback() {

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(playAnimation)
}

function playAnimation() {

    AnimationExtender.Enabled = true;
    var onclkBehavior = $find("ctl00_btnOpenList").get_OnClickBehavior().get_animation();
    onclkBehavior.play();
    AnimationExtender.Enabled = false;
}

As an aside, it seems your general approach may face issues if there is a delay in receiving the pageRequest. It may be a bit weird to click a button and several seconds later have the animation happen. It may be better to either pre-load the data, or to pre-fill the div with some "Loading..." thing, make it about the right size, and then populate the actual contents when it arrives.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文