jquery 同时淡入淡出

发布于 2024-12-22 21:03:18 字数 598 浏览 2 评论 0原文

我试图淡出对话框的现有文本,然后同时淡入错误图像。

我该怎么做?现在我已经(在某种程度上)工作了,但有一些问题。

  1. 它立即淡出
  2. 它不是同时的(我希望 1 淡入,而另一个淡出)。

注意:我不能只是淡入 div,因为整个程序 #dialog 都被写入,所以如果我将 div.error 存储在那里,它就会被覆盖,所以我需要这样做。

到目前为止我所拥有的

$.ajax({
            type: "POST",
            url:  "/checkstatus/" + id,
            dataType: "html",
            error: function(data){
                $("#dialog").fadeOut();
                $("#dialog").hide().html("<img src='/img/deleted.jpg' alt='deleted'>")
                $("#dialog").fadeIn();
            }
        });

I am trying to fade out the existing text of a dialog box, and then fade in an error image simultaneously.

How might i do this? Right now I have it (somewhat) working but a few things wrong with it.

  1. it fades out instantly
  2. its not simultaneous (i want 1 to fade in while the other fades out).

Note: I cant just fade in a div because throughout the whole program #dialog is being written to, so if I stored the div.error in there it would just be overwritten, so i need to do it this way.

what i have so far

$.ajax({
            type: "POST",
            url:  "/checkstatus/" + id,
            dataType: "html",
            error: function(data){
                $("#dialog").fadeOut();
                $("#dialog").hide().html("<img src='/img/deleted.jpg' alt='deleted'>")
                $("#dialog").fadeIn();
            }
        });

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

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

发布评论

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

评论(2

茶底世界 2024-12-29 21:03:18
$.ajax({
    type: "POST",
    url:  "/checkstatus/" + id,
    dataType: "html",
    error: function(data){
        $("#dialog").fadeOut(function(){
             $("#dialog")
                .html("<img src='/img/deleted.jpg' alt='deleted'>")
                .fadeIn()
        });

    }
});
$.ajax({
    type: "POST",
    url:  "/checkstatus/" + id,
    dataType: "html",
    error: function(data){
        $("#dialog").fadeOut(function(){
             $("#dialog")
                .html("<img src='/img/deleted.jpg' alt='deleted'>")
                .fadeIn()
        });

    }
});
风启觞 2024-12-29 21:03:18

您不能让一个对象同时淡出和淡入 - 该对象一次只能有一种状态(淡入或淡出,但不能同时淡入和淡出两者)。

如果您确实想要这种视觉效果,则需要两个单独的对象,一个淡出,另一个淡入。例如,当淡出一张图像并同时淡入下一张图像时,这就是多少幻灯片的工作原理。它们实际上是淡出一个对象并淡入另一个对象。

因此,如果您确实希望对话框具有同时淡入淡出的视觉效果,则需要两个对话框,一个淡出,另一个淡入。

如果您愿意按顺序执行它们,则旧对话框会淡出,然后然后新的淡入淡出(两个淡入淡出是一个接一个,而不是同时进行),然后您可以使用 Vitaly 提出的代码类型,在其中执行 fadeOut(),然后,在补全函数中对于fadeOut(),您可以更改对话框的内容,然后执行fadeIn()

如果您有理由只需要一个对话框并希望同时淡入淡出,那么您可以 fadeOut() 对话框中的一个内容块并 fadeIn 另一内容块。您可以将每个内容块放在同一个对话框内其自己的 div 中,然后将一个内容淡出,另一个淡入。您还必须手动将两个 div 放置在彼此之上(重叠)。这是可能的,但需要更多的工作。

You cannot have one object fadeOut and fadeIn at the same time - the object can only have one state at a time (it's either fading in or fading out, but not both).

If you really want that visual effect, you will need two separate objects and one fades out and the other fades in. For example, that's how many slideshows work when they fade out one image and, at the same time, fade in the next image. They are actually fading out one object and fading in another.

So, if you really wanted that dual fade at the same time visual effect for your dialog, you would need two dialogs, one fading out and the other fading in.

If you're willing to do them sequentially so the old dialog fades out and then the new one fades in (the two fades are one after the another rather than at the same time), then you can use the type of code that Vitaly proposed where you do the fadeOut() and then, in the completion function for that fadeOut(), you change the contents of the dialog and then do a fadeIn().

If you had reasons to only want one dialog and want the simultaneous fades, then you could fadeOut() one block of content in the dialog and fadeIn another block of content. You would put each block of content in it's own div inside the same dialog and fade one out and the other in. You'd have to manually position both divs to be on top of one another (overlaid) too. It's possible, but takes a little more work.

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