【发布时间】:2012-11-14 08:03:18
【问题描述】:
我正在开发一个 jQuery 插件,当我单击暂停链接时,我需要在插件中调用一个函数。我的代码是这样的
$("#pauseAnimation").click(function () { $.fn.cjImageVideoPreviewer().pauseAnimation(); })
要调用的函数就是这个
(function ($) {
$.fn.cjImageVideoPreviewer = function (options) {
var settings = {
// user editable settings
images: [],
delay: 1000,
autoPlay: false,
showProgress: false
};
var sys = {
// function parameters
version: '1.0.2',
elem: null,
idx: 1,
timer: null,
loaded: 0,
mouseX: null,
mouseY: null,
state: false
};
/*
handle transitions
***************************************/
function clearTimer() {
if (sys.timer !== null) {
window.clearTimeout(sys.timer);
sys.timer = null;
}
}
// reset everything
function stopAnimation() {
if (sys.state) {
clearTimer();
sys.idx = 0;
sys.state = false;
// show the first image
$(sys.elem).find("div.cjImageVideoPreviewer img:first").css({
"display": "block"
});
// hide all the other images
$(sys.elem).find("div.cjImageVideoPreviewer img:not(:first)").css({
"display": "none"
});
}
}
// pause
function pauseAnimation() {
if (sys.state) {
clearTimer();
sys.idx = 0;
sys.state = false;
}
}
当我点击链接时出现错误
Microsoft JScript 运行时错误:对象不支持此属性或方法 任何帮助都会很明显..
【问题讨论】:
-
你的
cjImageVideoPreviewer函数返回this,所以它是可链接的吗? -
您的插件是否公开了这些功能中的任何一个?
-
您可能不想将其称为
$.fn.cjImageVideoPreviewer().,而是称为$.cjImageVideoPreviewer().。
标签: javascript jquery