繁体   English   中英

加载外部javascript文件时,Colorbox延迟打开并“锁定”

[英]Colorbox delay to open and “lock” when load external javascripts files

我正在使用colorbox在我的项目中加载模式页面。 当我单击以打开一个模态时,页面需要花费一些时间来加载,并且窗口在一段时间内“锁定”。 我做了一个简单的页面来表示我的问题。 访问: http : //testes.tiagocrizanto.com/当您单击Index2时,页面将正常加载,但是,当您单击“模态”链接时,模态会花费一些时间来加载(请注意,加载图像会锁定一段时间)。 如果您打开Chrome DevTools并选择“网络”标签,则会看到加载到模式窗口中的外部js文件需要花一些时间才能加载。 在我的示例中,加载该窗口需要一段时间,但是,如果尝试加载3个或更多js文件,则模式窗口可能需要10秒钟或更长时间才能加载。

Index2页面的代码到和加载模式的脚本:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index2
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    $(document).ready(function () {
        $('.cbox').colorbox({
            innerWidth: 833,
            innerHeight: 500,
            scrolling: true
        });
    });
    </script>
    <a href="/Home/Modal" class="cbox">Modal</a>
</asp:Content>

模态代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Modal.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/ScriptFile.js") %>"></script>


    <h2>Modal</h2>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
</asp:Content>

任何想法为什么会发生?

经过loooonnngggg搜索后,我找到了解决方案: 优化颜色框并添加额外的jQuery

ColorBox使用jQuery的load()方法进行ajax处理,因此您只需要在链接的href中添加所需的选择器即可。

$(document).ready(function () {
     $('.cbox').colorbox({
         href: function () {
             return $(this).attr('href');
         },
         innerWidth: 833,
         innerHeight: 500,
         scrolling: true
     });
 });

链接按钮:

<%: Html.ActionLink("Add", "Create", "Agenda", new { @class = "btn btn-mini pull-left margin-10 no-margin-left border-radius-3 cbox" })%>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM