此脚本在除 Google Chrome 之外的所有浏览器中都能完美运行。
$(document).ready(function(){
$(".banners-anim img").each(function(){
var hover_width = $(this).width();
var hover_height = $(this).height();
var unhover_width = (hover_width - 30);
$(this).width(unhover_width);
var unhover_height = $(this).height();
$(this).closest("li").height(unhover_height);
var offset = "-" + ((hover_height - unhover_height)/2) + "px";
$(this).closest("span").css({'position':'absolute', 'left':'0', 'top':'25px', 'width':'100%'});
$(this).hover(function(){
$(this).animate({width: hover_width, marginTop: offset}, "fast")
},function(){
$(this).animate({width: unhover_width, marginTop: 0}, "fast")
});
});
});
Chrome 无法识别更改后的图像属性。
当img的宽度
改变时,高度
也会改变。即使不在 Chrome 中..
$(this).width(unhover_width);
var unhover_height = $(this).height();
unhover_height
给出 0
。
此脚本的完整代码(包括 html)- http://jsfiddle.net/BsqTe/
请帮忙解决这个问题。
谢谢。
最佳答案
如果您正在 jQuery ready
函数中处理图像,则需要记住图像可能尚未加载。 jQuery ready
函数的目的是在 DOM 准备好后立即触发,即使图像仍在加载。如果您想在所有图像加载完成后执行某些操作,请使用 window
的 load
事件:
$(window).load(yourFunctionHere);
关于jQuery && 谷歌浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3070316/