jquery animate() 问题(语法?)
$('#somediv').stop(false, true)
.animate({marginLeft: '-=' + e.width() + 'px'}, options.speed, function(){ options.onNewSlide() })
e.with()
返回 640options.speed
包含 800options.onNewSlide()
包含自定义回调函数
它在 Firefox 中工作正常。但我用 jQuery-Lint 对其进行了调试,因为它在 IE 中抛出了一些随机错误。 Lint 告诉我:
When I called animate(...) with your args, an error was thrown! TypeError: c.speed is not a function { message="c.speed is not a function", more...}
You passed: [Object { marginLeft="-=640px"}, 800, function()]
它指示我发布的行。 我已经检查了 jQuery 文档,但我的语法没问题。
你知道我做错了什么吗?
PS:我使用 Google API 中的 jQuery 1.4.2,您可以在此处看到错误: http://meodai.ch/ slider/ (我知道代码正在构建中,但仍然)
编辑: 我尝试在新文件中仅使用动画重现错误: http://meodai.ch/ slider/index2.html 在那里它工作得很好!现在我迷路了。
$('#somediv').stop(false, true)
.animate({marginLeft: '-=' + e.width() + 'px'}, options.speed, function(){ options.onNewSlide() })
e.with()
returns 640options.speed
contains 800options.onNewSlide()
contains a a custom callback function
It works fine in Firefox. But i debugged it with jQuery-Lint because it was throwing some random error in IE. Lint tells me:
When I called animate(...) with your args, an error was thrown! TypeError: c.speed is not a function { message="c.speed is not a function", more...}
You passed: [Object { marginLeft="-=640px"}, 800, function()]
and it indicates me the line i have posted.
I have checked the jQuery doc, but my syntax seams ok.
Do you know what I am doing wrong?
PS: I use jQuery 1.4.2 from the Google API you can see the error here: http://meodai.ch/slider/ (I know the code is under construction, but still)
edit:
I have tried to reproduce my error in a new file with just the animation: http://meodai.ch/slider/index2.html there it works very well! Now I am lost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的代码中,您有:
当
options
为undefined
时,这会使用defaultOptions
中的属性扩展 jQuery 对象。defaultOptions
中有speed
和easing
属性,它们会覆盖 jQuery 的同名内部属性,从而导致错误。结合
defaultOptions
和options
的更安全方法是:In your code you have:
When
options
isundefined
, this extends the jQuery object with the properties fromdefaultOptions
.Within
defaultOptions
arespeed
andeasing
properties, which overwrite jQuery's internal properties of the same names, causing the error.A safer way to combine
defaultOptions
andoptions
would be:我看到的一件事是您没有指定要使用的缓动函数。尝试
One thing that I see is that you are not specifying the easing function to use. Try
我为我的参数创建了一个对象
options
。在选项对象内部,我重命名该选项后,我的问题就得到了解决。但为什么我在其他测试页上没有遇到同样的问题呢?I have made an object
options
for my params. inside the option object i hadspeed:
andeasing:
as soon as i renamed that options my problem was solved. But how does it comes that i don't have the same problem on my other test page?