简体   繁体   English

我的jQuery加载叠加层不会每次都显示

[英]My jquery loading overlay doesn't show up every

For whatever reason, my jquery loading overlay doesn't load at all under any circumstance even though the same code was working just days ago. 无论出于何种原因,即使几天前同一代码仍在工作,我的jquery加载叠加层在任何情况下都不会加载。 Well, not the exact same code. 好吧,不是完全相同的代码。 I have been trying to get the overlay to resize with the window, and I have been trying different things, but I don't understand what I did that caused the overlay to never even show up? 我一直在尝试使覆盖层与窗口一起调整大小,并且尝试了不同的操作,但是我不知道我所做的事情导致覆盖层甚至无法显示? Here is the code that should attach to the overlay to the correct div... 这是应该附加到正确的div上的代码。

function MRNSearchInternals()
{
    //debugger;
    var form = $("#MRNSearch");
    $div = $("#TabView1");
    var srlzdform = form.serialize();
    var PopID = <% =PopID %>;
    var options = [];
    var $url = $("#target").attr("action");
    $('<div id="overlay">').css({
        position: 'absolute',
        opacity: 0.2,
        top : $div.offset().top,
        left : $div.offset().left,
        width : $div.offset().width,
        height : $div.outerHeight(),
        background: 'blue url(<%=Url.Content("~/images/ajax-loader.gif")%>) no-repeat center'
    }).hide().appendTo($div);    

    $("#overlay").fadeIn();
    $.post('<%:Url.Action("SearchByMRN", "PatientACO")%>', srlzdform, function (data) 
    {                   
        DisplayDemographicSearch(data);
        $("#overlay").fadeOut();
    });
}

Notice how I create the div. 注意我如何创建div。 I give it an id, and then I call it's css atribute. 我给它一个id,然后称它为css属性。 From there I set all the css attributes. 从那里,我设置所有css属性。 I then attempt to call fadeIn, and fadeOut after the ajax call. 然后,我尝试在ajax调用之后调用fadeIn和fadeOut。 Any body have any idea why this isn't working? 任何机构都知道为什么这不起作用? Any help would be great. 任何帮助都会很棒。

Some More clarification 一些澄清

Also notice how I chose the div to overlay. 还要注意我如何选择div进行叠加。 I get a div id from my dom 我从我的家中获得了一个div ID

    $div = $("#TabView1");

Also, I looked the source, and I do have that particular div in there. 另外,我查看了源代码,并且确实有该特定的div。 So that is not the problem. 所以那不是问题。 Somehow or the other, it simply isn't showing up. 无论如何,它根本没有显示出来。 UPDATE: The DOM I get Below is what is produced from the jquery code. 更新:我从下面得到的DOM是从jQuery代码生成的。 It appears as though everything is being created fine. 似乎一切都创建得很好。 Note also, that display is set to none. 另请注意,该显示设置为无。 That is what I would expect since I have the overlay fade out. 这就是我所期望的,因为我的叠加层逐渐消失了。 My question is why does it never show up. 我的问题是为什么它永远不会出现。

<div class="TabView" id="TabView1">
    <div class="Tabs">...</Tabs>
    <div class="Pages">
    <div id="overlay" style="left: 114px; top: 205px; height: 452px; display: none; position: absolute; opacity: 0.2; background-image: url("/images/ajax-loader.gif"); background-attachment: scroll; background-repeat: no-repeat; background-position-x: center; background-position-y: center; background-size: auto; background-origin: padding-box; background-clip: border-box; background-color: blue;"/>
</div>

Well, the better way to create the overlay div would be 好吧,创建叠加层div的更好方法是

$('<div/>', {
    id: 'overlay'
})

Does that solve the problem? 这样可以解决问题吗? Otherwise, the ID might not be created, or does it? 否则,可能不会创建ID,还是会创建?

Update for the edit from your post: the "width" attribute is not set on the created overlay. 更新帖子的内容:未在创建的叠加层上设置"width"属性。 What happens if that is added and set to eg 100px? 如果将其添加并设置为100px会怎样? It seems like there is something wrong with the setting of the width attribute (or the getting of the width attribute of $div). 似乎width属性的设置(或$ div的width属性的获取)有问题。

Is this code called more than once? 该代码是否被多次调用? If so, are you removing #overlay somewhere? 如果是这样,您是否要删除某个地方的#overlay

Calling this code multiple times would create duplicate #overlay dom nodes which is a no-no and could explain why it doesn't work sometimes. 多次调用此代码将创建重复的#overlay dom节点,这是不行的,并且可以解释为什么有时不起作用。

To remove it, change: 要删除它,请更改:

$("#overlay").fadeOut();

to: 至:

$("#overlay").fadeOut('slow', function () {
    $("#overlay").remove();
});

Your selector doesn't look right. 您的选择器看起来不正确。

I would try: 我会尝试:

$('#overlay').css. $('#overlay')。css。 . . .

function MRNSearchInternals()
{
    //debugger;
    var form = $("#MRNSearch");
    $div = $("#TabView1");
    var srlzdform = form.serialize();
    var PopID = <% =PopID %>;
    var options = [];
    var $url = $("#target").attr("action");
    $('<div id="overlay">').css({
        position: 'absolute',
        opacity: 0.2,
        top : $div.offset().top,
        left : $div.offset().left,
        width : $div.offset().width, //<- The problem is right here should be $div.width
        height : $div.outerHeight(),
        background: 'grey url(<%=Url.Content("~/images/ajax-loader.gif")%>) no-repeat center'
    }).hide().appendTo($div);    

    $("#overlay").fadeIn();
    $.post('<%:Url.Action("SearchByMRN", "PatientACO")%>', srlzdform, function (data) 
    {                   
        DisplayDemographicSearch(data);
        $("#overlay").fadeOut('slow', function () {
             $("#overlay").remove();
        });
    });
}

Man. 男人。 That was real hard to debugg. 确实很难调试。 I wish Visual studio 2010 had better jquery debugging capability. 我希望Visual Studio 2010具有更好的jquery调试功能。 Thankfully, the next version is supposed to be a better jquery debugger. 值得庆幸的是,下一个版本应该是更好的jquery调试器。 But, the problem was the width attribute. 但是,问题是width属性。

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

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