[英]jQuery run when assets load
I have a big image which is full width and full height, I have a jQuery script with document.ready but the script runs still before the image is loaded. 我有一个全宽和全高的大图像,我有一个带有document.ready的jQuery脚本,但是该脚本在图像加载之前仍然运行。 Can I prepare the statement in another way so the image loads.
我可以用另一种方式准备语句,以便加载图像。
$(document).ready(function(){
var currWidth = $(window).width();
console.log(currWidth);
var startPos = -100;
var endPos = (currWidth / 2) + (startPos / 2);
console.log(endPos);
$('#welcome').animate({left: endPos}, 1000);
});
http://jsfiddle.net/KtUEL/151/ http://jsfiddle.net/KtUEL/151/
$(window).load(function() { $(window).load(function(){
This instead of document.ready this fully loads the dom and all assets document.ready just loads the page. 这将代替document.ready完全加载dom和所有资产document.ready仅加载页面。
thanks! 谢谢!
Solved 解决了
You can also do this as part of the html of your image via the onload event: 您也可以通过onload事件将其作为图像html的一部分来执行:
<img src="..." onload="myFunction()" />
This will trigger myFunction when that particular image is loaded rather than when the entire page has loaded. 当加载特定图像而不是加载整个页面时,这将触发myFunction。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.