仅在 IE7 中出现 JavaScript 错误(jQuery / Cycle.js
我正在使用 jQuery 和 Cycle.js 淡入淡出该网站上的一些图像。
在第一张和最后一张幻灯片上,我放置了一个回调函数来转到下一页/上一页,但是在 IE7 中我收到运行时 javascript 错误(在任何其他浏览器中都没有)。
这是我的 javascript 文件的链接: http://bit.ly/dAKEof
我收到的错误IE7 是:
行:126 字符:4 错误:需要对象 代码: 0
这是我在functions.js文件第126行的代码:
window.location = $('#next').find("a").attr("href");
有什么想法吗?
I'm using jQuery and cycle.js to fade through some images on this site.
On the first and last slides, I've put a callback function to go to the next/prev pages, however in IE7 I'm receiving a runtime javascript error (not in any other browsers).
Here's the link to my javascript file: http://bit.ly/dAKEof
The error I'm receiving in IE7 is:
Line: 126
Char: 4
Error: Object Expected
Code: 0
Here's the code I have at line 126 of the functions.js file:
window.location = $('#next').find("a").attr("href");
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有看到您问题中出现错误的网站链接,但在您的个人资料中看到了一个网址,然后去那里查看是否就是这个网址。看起来是这样……
IE 因在 JavaScript 错误中给出不正确的行号而臭名昭著。错误实际上出现在第 125 行:
ops
对象中的end
函数为 null,这就是错误所在。有趣的是,我也检查了 FF,那里也是如此,但在这种情况下,它似乎比 IE 恢复得更优雅。从代码的其余部分来看,尚不完全清楚 onBefore 函数是如何被调用的。看起来可能是循环插件本身。无论如何,无论调用发生在哪里,
opts
对象似乎都没有填充函数所需的所有数据。更新:
我查看了cycle插件代码,
opts.end
是插件用户必须提供的回调。因此,问题的解决方案是在创建循环对象(js 文件中的第 101 行)时提供自己的回调,或者删除代码中调用end
函数的行。更新以响应下面OP的评论:
经过仔细检查,您的代码实际上将完全按照您想要的方式执行,而无需调用
end
回调,因此您可以安全地删除这些行。该插件会在执行任何动画之前触发您的onBefore
回调。由于您在从第一张幻灯片向后移动或从最后一张幻灯片向前移动时在浏览器中重新加载新网址,因此它甚至永远不会达到淡入淡出动画,而这正是您的目标。但是,要回答有关如何向原始循环对象添加
end
回调的问题,您可以按照onBefore
和onAfter
的方式进行操作。代码>.使用您想要执行的任何代码创建一个函数,然后在传递给插件的对象哈希中包含end: yourFuncName
。停止循环插件的另一种方法是$(selector).cycle('stop');
。但同样,您的情况不需要这些。只需删除对end
的调用就可以了。I didn't see a link to the site with the error in your question but saw a url in your profile and went there to see if that might be the one. Looks like it is...
IE is notorious for giving incorrect line numbers in its javascript errors. The error is actually on line 125:
The
end
function in theops
object is null, and that's where the error is. Interestingly, I checked in FF as well and this is also true there, but it seems to recover more gracefully than IE in this case.It's not entirely clear from the rest of the code how the
onBefore
function gets called. Looks like it might be the cycle plugin itself. In any event, wherever that call happens theopts
object appears to not be getting populated with all the data that is needed by your function.Update:
I took a look at the cycle plugin code and
opts.end
is a callback that the user of the plugin must supply. So the solution to your problem is to either provide your own callback when you create the cycle object (line 101 in your js file) or remove the lines in your code that invoke theend
function.Update in response to OP's comment below:
Upon closer inspection your code will actually do exactly what you want without the need to invoke an
end
callback, so you can safely remove those lines. The plugin triggers youronBefore
callback before it does any animations. And since you reload a new url in the browser when moving backward from the 1st slide or forward from the last one, it never even gets to the fade animation, which is your goal.However, to answer your question on how to add an
end
callback to the original cycle object, you would do it exactly as you did foronBefore
andonAfter
. Create a function with whatever code you want to execute and then includeend: yourFuncName
in the object hash passed to the plugin. Another way to stop the cycle plugin is$(selector).cycle('stop');
. But again, none of this is needed in your case. Just remove the calls toend
and you should be fine.