gpt4 book ai didi

chrome 零中的 jquery 高度

转载 作者:行者123 更新时间:2023-12-01 02:59:09 24 4
gpt4 key购买 nike

我将capty附加到图像上,我这样做

$(document).ready(function(){
$('.shop_banner img').capty({height:150});
});

在 chrome 中,当我调试 capty 代码时 alert($this.height()) 为零,因此包装器隐藏图像。我知道某些浏览器希望图像完全加载,但如果我使用 ready 并不意味着它在页面完全加载后执行?我能做什么?

最佳答案

不,load和准备好不是一回事。

你可以做到

$(window).load(function(){
$('.shop_banner img').capty({height:150});
});

ready DOM 准备好后立即调用您的函数,这并不意味着图像已加载。

来自文档:

While JavaScript provides the load event for executing code when a page is rendered, this event does not get triggered until all assets such as images have been completely received. In most cases, the script can be run as soon as the DOM hierarchy has been fully constructed. The handler passed to .ready() is guaranteed to be executed after the DOM is ready, so this is usually the best place to attach all other event handlers and run other jQuery code. When using scripts that rely on the value of CSS style properties, it's important to reference external stylesheets or embed style elements before referencing the scripts.

In cases where code relies on loaded assets (for example, if the dimensions of an image are required), the code should be placed in a handler for the load event instead.

关于chrome 零中的 jquery 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13611988/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com