我在这里与Google Chrome有一些小问题。我的代码在Safari上运行得非常好,这让我认为它应该可以在谷歌浏览器上正常运行。但Chrome并没有按照预期制作动画。什么可能是错的?jQuery Animate无法在Chrome上工作
$(function() {
var sourceFoto = $(".empreendimento .main-photo img").attr("src");
var alturaFoto;
var larguraFoto;
var limiteX;
var limiteY;
$(document).load(sourceFoto, function() {
alturaFoto = $(".empreendimento .main-photo img").height();
larguraFoto = $(".empreendimento .main-photo img").width();
limiteY = Math.round(alturaFoto - 420);
limiteX = Math.round(larguraFoto - 580);
$(".empreendimento .main-photo img").animate({
marginLeft: "-" + limiteX
}, 5000, 'jswing').animate({
marginTop: "-" + limiteY
}, 5000, 'jswing').animate({
marginLeft: "0px"
}, 5000, 'jswing').animate({
marginTop: "0px"
}, 5000, 'jswing');
});
});
编辑
我已经找到了答案。刚刚加载图像onLoad
方法,工作得很好。
image = new Image();
image.onload = function() {
alturaFoto = $(".empreendimento .main-photo img").height();
larguraFoto = $(".empreendimento .main-photo img").width();
limiteY = Math.round(alturaFoto - 420);
limiteX = Math.round(larguraFoto - 580);
$(".empreendimento .main-photo img").animate({
marginLeft: "-" + limiteX
}, 5000).animate({
marginTop: "-" + limiteY
}, 5000).animate({
marginLeft: "0px"
}, 5000).animate({
marginTop: "0px"
}, 5000);
}
image.src = sourceFoto;
您是否检查过您在两种浏览器中传入animate方法的值是否相同?如果是这样,也许这是一个jQuery错误。如果没有,解决这个问题。 – 2012-03-05 15:04:39
在控制台中是否有任何错误? – danwellman 2012-03-05 15:04:47
你的控制台中是否有错误? (在浏览器中点击F12,然后浏览到页面,在右下角看看是否有错误,如果有错误,请点击通知,看看它是怎么回事。) – JasCav 2012-03-05 15:05:18