当然,我做错了事,但无法弄清楚是什么。
我有一个灯箱出现在此软件包中:featherlight.js
编辑:有人评论以确保其被调用。我可以确认它正在被调用。我用console.log
测试了返回灯箱的宽度和高度。
文档显示,它需要250毫秒才能显示。 我这样称呼它:
$.featherlight("#previewCompleteContainer",{afterOpen: function(event) {
setTimeout( function(){ sizeText(); },360)
} })
考虑到它需要250毫秒才能显示,因此我在360毫秒处添加了一个回调sizeText()
。
这样一来,我可以获得框的尺寸,然后计算出一些适合的文本。如果您想知道为什么要添加360ms“ afterOpen”,那是因为回调不等到afterOpen
由于某些原因。
function sizeText() {
$("#img_preview_text_container").css("width","300px");
}
sizeText
方法尝试将div的宽度设置为300px。但是,没有积极的事情发生。
这是出现在屏幕上的html:
<div class="featherlight-content"><button class="featherlight-close-icon featherlight-close" aria-label="Close">✕</button><div id="previewCompleteContainer" class="featherlight-inner">
<img src="https://example.com/Guzman.jpg?629" alt="" style="width:100%;" id="preview_image_img">
<div id="img_preview_text_container" style="position: absolute; top:120px; left:56px"><div id="custom1Text" style="background-color: red; width: auto; height: auto; white-space: nowrap; display: inline-block;">GuzmanO</div></div>
</div></div>
我希望
$("#img_preview_text_container").css("width","300px");
更新div,但没有发生。没错,就是行不通。 知道我在做什么错吗?