代码之家  ›  专栏  ›  技术社区  ›  Sailing Judo

如何在文档加载后淡出一个DIV?[关闭]

  •  1
  • Sailing Judo  · 技术社区  · 16 年前

    我试着做一些我认为很简单的事情,但实际上我没有任何运气让它工作。我只想在文档加载完成后经过x秒后淡出一个DIV。

    在我的网站.master文件中,我有以下内容:

    <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <!-- various other links, etc commented for brevity -->
        <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-1.2.6.js")%>"></script>
    
        <script type="text/javascript">
        $(document).ready(function() {
            $("#notify-container").fadeOut(2000);
        }
        </script>
    
    </head>
    
    <body class="page">
        <%
        if (Html.ViewContext.TempData.ContainsKey("StatusMessage")) {
            %>
            <div id="notify-container"><%=Html.ViewContext.TempData["StatusMessage"]%></div>
            <%
        }
        %>
        <asp:ContentPlaceHolder ID="MainContent" runat="server" />
    </body>
    </html>
    

    问题是什么都不会消失。我忽略了什么?

    3 回复  |  直到 16 年前
        1
  •  9
  •   hugoware    16 年前

    $(document).ready(function() {
        $("#notify-container").fadeOut(2000);
    }
    

    $(document).ready(function() {
        $("#notify-container").fadeOut(2000);
    }); // <---
    
        2
  •  3
  •   Acorn    16 年前

    );
    

        3
  •  0
  •   Sneakyness    16 年前

    .fadeTo(delaytime, 1); delaytime 会是你想拖延多久。它只是将已经完全可见的对象“淡出”到它已经拥有的值,浪费了你告诉它的确切时间。