jQuery、IE、无效参数
我用 jQuery 编写了一个简单的滑动画廊。它是一个狭窄的容器,内部有一个宽表格,可以通过 .animate() 更改其“left”属性,
在 Firefox、Safari 和 IE8 上运行良好。但是我在使用 Internet Explorer 7 及更低版本时遇到问题。
弹出一条错误消息,提示“脚本错误”。行:4619。字符:4。错误:参数无效。网址:http://www.imagina.com.uy/bentancorleborgne/?page_id= 2
该行只能位于 jQuery.js 文件内。因为它是唯一一个超过 6k 行的文件。
所以我想知道。到底是怎么回事!!
仅当我按箭头对图库进行动画处理时,才会弹出该错误。所以我留下了脚本的代码,以防万一您可以从那里得到一些线索。
任何帮助或线索将不胜感激。提前致谢!!
$(document).ready(function() {
var tablaWidth = parseFloat($('.imagenesWrapper table').width());
var tdWidth = parseFloat( $('.imagenesWrapper table tr td').outerWidth() ) + parseFloat( $('.imagenesWrapper table tr td').css('marginRight') );
var cantCeldas = tablaWidth / tdWidth - 1;
var posActual = 0;
var leftCSS = 1;
if(cantCeldas==0) {
$('#leftArrow').hide();
$('#rightArrow').hide();
}
else
$('#rightArrow').show();
$('#rightArrow').click(function() {
if(leftCSS < tablaWidth) {
posActual += 1;
leftCSS = moverTabla(posActual, cantCeldas, tdWidth);
}
});
$('#leftArrow').click(function() {
if(posActual > 0) {
posActual -= 1;
leftCSS = moverTabla(posActual, cantCeldas, tdWidth);
}
});
});
function moverTabla(pos, cantidad, tdWidth) {
var leftCSS = pos * tdWidth;
$('.imagenesWrapper table').animate( {left: '-' + leftCSS +'px'}, 'slow');
mostrarOcultarFlechas(pos, cantidad);
return leftCSS;
}
function mostrarOcultarFlechas(pos, cantidad) {
//mostrar-ocultar flecha izquierda
if(pos==0)
$('#leftArrow').hide();
else if($('#leftArrow').css('display') == 'none')
$('#leftArrow').show();
//mostrar-ocultar flecha derecha
if(pos==cantidad)
$('#rightArrow').hide();
else if($('#rightArrow').css('display') == 'none')
$('#rightArrow').show();
}
I coded a simple sliding gallery with jQuery. It's a narrow container with a wide table inside that changes it's 'left' property through .animate()
Works beautifully on Firefox, Safari and IE8. However i'm having an issue with internet explorer 7 and below.
A message error pops up saying 'script error. line: 4619. char: 4. error: invalid argument. url: http://www.imagina.com.uy/bentancorleborgne/?page_id=2
That line can only be inside the jQuery.js file. Since it's the only file with 6k+ lines.
So I'm wondering. What the hell is going on!!
The error only pops up when I press the arrow to animate the gallery. So I'm leaving the script's code just in case you can get some clue from there.
Any help or clue would be geatly appreaciated. Thanks in advance!!
$(document).ready(function() {
var tablaWidth = parseFloat($('.imagenesWrapper table').width());
var tdWidth = parseFloat( $('.imagenesWrapper table tr td').outerWidth() ) + parseFloat( $('.imagenesWrapper table tr td').css('marginRight') );
var cantCeldas = tablaWidth / tdWidth - 1;
var posActual = 0;
var leftCSS = 1;
if(cantCeldas==0) {
$('#leftArrow').hide();
$('#rightArrow').hide();
}
else
$('#rightArrow').show();
$('#rightArrow').click(function() {
if(leftCSS < tablaWidth) {
posActual += 1;
leftCSS = moverTabla(posActual, cantCeldas, tdWidth);
}
});
$('#leftArrow').click(function() {
if(posActual > 0) {
posActual -= 1;
leftCSS = moverTabla(posActual, cantCeldas, tdWidth);
}
});
});
function moverTabla(pos, cantidad, tdWidth) {
var leftCSS = pos * tdWidth;
$('.imagenesWrapper table').animate( {left: '-' + leftCSS +'px'}, 'slow');
mostrarOcultarFlechas(pos, cantidad);
return leftCSS;
}
function mostrarOcultarFlechas(pos, cantidad) {
//mostrar-ocultar flecha izquierda
if(pos==0)
$('#leftArrow').hide();
else if($('#leftArrow').css('display') == 'none')
$('#leftArrow').show();
//mostrar-ocultar flecha derecha
if(pos==cantidad)
$('#rightArrow').hide();
else if($('#rightArrow').css('display') == 'none')
$('#rightArrow').show();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 IE7- 为
$('.imagenesWrapper table tr td').css('marginRight' 返回
auto
)因此,
parseFloat()
返回NAN
(不是数字),之后一切都会失败......检查原因。 。
The problem is that IE7- returns
auto
for the$('.imagenesWrapper table tr td').css('marginRight')
So the
parseFloat()
returnsNAN
(not a number) and everything fails after that..checking for the reason ..