我在使用 jQuery Cycle 幻灯片放映的当前幻灯片更新 DIV 的内容时遇到困难。
这是 slider 函数,它目前将输出当前幻灯片作为警报(并且有效)。
$(function () {
$('#slideshow').cycle({
fx: 'none',
timeout: 1,
continuation: 1,
speed: 'fast',
before: function (curr, next, opts) {
alert("Current slide " + opts.currSlide);
}
});
DIV如下:
<div id="test">Hello</div>
我正在尝试使用的代码(替换上面代码的末尾):
$(function (curr, next, opts) {
var test = document.getElementById("test");
test.innerHTML = opts.currSlide;
});
关于为什么 DIV 不更新当前幻灯片 # 的任何想法? 不幸的是,没有任何反应。我仍在学习 JS,所以非常感谢任何指点!感谢您的宝贵时间。
最佳答案
opts
对象 (opts.currSlide
) 中的变量未在循环函数/插件之外定义
所以你必须将它传递给函数
$(function () {
$('#slideshow').cycle({
fx: 'none',
timeout: 1,
continuation: 1,
speed: 'fast',
before: function (curr, next, opts) {
getCurrSlide(opts.currSlide);
}
});
}):
function getCurrSlide(curr){
$("#test").html(curr);
}
关于javascript - 使用当前的 jQuery Cycle 幻灯片更新 DIV 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22382427/