【发布时间】:2013-04-23 03:31:20
【问题描述】:
大家下午好, 我已经设法编写了一个脚本来计算图像的宽度和高度,并在图像的右下角正确放置一串文本,以便与字幕/字幕一起使用。
我已经设法让它在除 IE8 之外的所有浏览器中完美地生成、计算和显示。出于某种原因,它在 IE8 中炸毁了屏幕,我似乎无法弄清楚它为什么会这样做,并改进我的 JavaScript 以在使用 IE8 时可能具有用于计算的条件函数。
有什么建议吗?
http://jsfiddle.net/jodriscoll/u26vZ/
$(function ($) {
// jQuery is passed as the first arg $
$('.img-right img,.img-left img').bind('load', function () {
var $img = $(this),
imgHeight = $img.height(),
imgWidth = $img.width();
$img.siblings('p').width(imgWidth);
$img.siblings('span').width(imgHeight);
$img.siblings('.credit').css({
left: imgWidth + 6,
top: imgHeight - 10
});
}).each(function () {
// we need to force the "load" event to fire if it was already complete:
// technique taken from https://gist.github.com/268257
if (this.complete || this.complete === undefined) {
var src = this.src;
// webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
// data uri bypasses webkit log warning
this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
this.src = src;
}
});
});
【问题讨论】:
-
您将覆盖
this.src两次。为什么会这样? -
做一些调试,看看数字在哪里以及为什么。
-
@roXon = 在此处阅读有关此方法的更多信息:groups.google.com/group/jquery-dev/browse_thread/thread/…
-
@Kevin B = 不确定这如何回答任何问题或提供任何指导说明,但我会继续研究。
-
逐行浏览,找出数字开始不同的地方。
标签: jquery vertical-alignment jquery-calculation vertical-text