javascript判断图片是否加载完成的方法推荐
作者:jingxian 时间:2024-05-29 22:12:05
load事件
<script type="text/javascript">
$('img').onload = function() {
//code
}
</script>
优点:简单易用,不影响HTML代码。
缺点:只能指定一个元素,javascipt代码必须置于图片元素的下方
jquery方法
<script type="text/javascript">
$(function(){
$('.pic1').each(function() {
$(this).load(function(){
$(this).fadeIn();
});
});
})
</script>
注意,不要在$(document).ready()里绑定load事件。
优点:可以批量绑定元素事件,并且不影响HTML代码内容
缺点:需要jquery库的支持,代码需要放置到需要操作元素的下方。
标签:javascript,图片,加载
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
MySQL表复合查询的实现
2024-01-15 19:49:20
![](https://img.aspxhome.com/file/2023/6/68586_0s.png)
在nginx中配置pathinfo模式支持thinkphp的URL重写
2024-05-03 15:50:48
python对数组进行反转的方法
2023-08-12 13:38:54
Python socket模块ftp传输文件过程解析
2021-04-17 02:22:59
SQL常用日期查询语句及显示格式设置
2024-01-25 06:57:37
python傅里叶变换FFT绘制频谱图
2023-06-30 09:44:07
基于python分析你的上网行为 看看你平时上网都在干嘛
2021-09-02 15:04:39
![](https://img.aspxhome.com/file/2023/6/103146_0s.gif)
Python+django实现文件上传
2022-08-31 20:52:22
Python和Go成为2019年最受欢迎的黑客工具(推荐)
2021-05-22 16:37:17
![](https://img.aspxhome.com/file/2023/8/131898_0s.png)
python GUI库图形界面开发之PyQt5线程类QThread详细使用方法
2023-12-03 20:29:40
![](https://img.aspxhome.com/file/2023/1/70221_0s.png)
python查询MySQL将数据写入Excel
2023-12-15 13:48:11
![](https://img.aspxhome.com/file/2023/8/70868_0s.png)
如何在Python中引用其他模块
2022-09-26 23:30:21
![](https://img.aspxhome.com/file/2023/2/69492_0s.png)
python变量赋值方法(可变与不可变)
2021-02-14 08:51:55
![](https://img.aspxhome.com/file/2023/9/69559_0s.jpg)
C#程序连接数据库及读取数据库中字段的简单方法总结
2024-01-15 18:01:51
MySQL数据库优化之索引实现原理与用法分析
2024-01-27 08:12:37
![](https://img.aspxhome.com/file/2023/9/112629_0s.png)
php出现Cannot modify header information问题的解决方法大全
2024-05-02 17:35:21
vue组件之间进行传值的方法
2024-04-27 15:48:04
![](https://img.aspxhome.com/file/2023/9/133149_0s.png)
python获取各操作系统硬件信息的方法
2021-03-29 17:09:05
Python matplotlib如何简单绘制不同类型的表格
2021-10-16 12:23:48
![](https://img.aspxhome.com/file/2023/7/75887_0s.png)
深入php内核之php in array
2024-05-13 09:23:55