简体   繁体   English

将HTML内容加载到DIV后调整颜色框的大小

[英]Resizing colorbox after loading HTML content into a DIV

I've ventured to any and all of the posts here about colorbox resizing issues, div properties and numerous other things! 我已经冒险到这里关于colorbox调整大小问题,div属性和许多其他事情的任何和所有帖子! Anyway, this very VERY simple piece of code is driving me up a wall and I wonder if it couldn't be answered? 无论如何,这段非常简单的代码正在把我推到墙上,我想知道它是否无法回答?

<script type="text/javascript">
$(document).ready(function () {
    $("#text").load("<%= Model.FileLocation %>");
    $.fn.colorbox.resize();
});
</script>
<div id="text"></div>

Above is the code (which, I would imagine - should work like a charm). 以上是代码(我想 - 应该像魅力一样)。 I've tried using a $.get and putting the resize in a callback, using timeouts and separating things with functions. 我尝试使用$ .get并将resize放入回调中,使用超时并使用函数分隔。

I've also verified that nothing is broken, the text is being loaded (doing an alert with $("#text") as the message shows me the loaded text. Also I can specify widths and/or heights for the resize function and they work find, however, I can't do this based on the loaded content. 我还验证了没有任何内容被破坏,正在加载文本(使用$(“#text”)进行警报,因为消息显示加载的文本。此外,我可以指定调整大小功能的宽度和/或高度然而,他们工作找不到,我根据加载的内容不能这样做。

Sorry for the long-winded post... any ideas why in the world this thing will not resize? 对不起啰嗦的帖子...任何想法,为什么在世界上这件事不会调整大小?

Try waiting until the content is actually loaded. 尝试等待,直到实际加载内容。

<script type="text/javascript">
$(document).ready(function () {
    $("#text").load("<%= Model.FileLocation %>", function() {
         $.fn.colorbox.resize();
    });
});
</script>
<div id="text"></div>

Thanks to anyone who read and tried to come up with a reason to why this didn't work, however, I finally found a work-around. 感谢任何阅读并试图找出原因导致其无效的人,我终于找到了解决办法。

It appears that for some reason, even putting the resize() in a success callback, it was still getting called too early. 看起来由于某种原因,即使将resize()置于成功回调中,它仍然过早被调用。 I was able to open firebug and manually enter the colorbox.resize() function in the command line and it worked just fine after loading, even though the callback failed. 我能够打开firebug并在命令行中手动输入colorbox.resize()函数,加载后它工作正常,即使回调失败。

So what I did was this 所以我做的就是这个

$(document).ready(function () {
        jQuery.ajaxSettings.async = false;

        $('#text').load('<%= Model.FileLocation %>');
        $.fn.colorbox.resize();
});

Setting the async in ajax to false forced it to be called in turn, and now it works great and is loading very quickly. 将ajax中的async设置为false迫使它依次被调用,现在它工作得很好并且加载速度非常快。

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

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