更新DIV内容与当前的jQuery循环幻灯片
Update DIV contents with current jQuery Cycle slide
我在用jQuery Cycle幻灯片的当前幻灯片更新div的内容时遇到困难。
这是滑动条函数,它当前将输出当前滑动条作为警报(并且工作)。
$(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);
}
OK。我做了一个小提琴,有几件事要注意。首先,当你点击按钮时,你添加到初始循环中的动作将被删除。在这里,我已经让初始循环做了你想做的事情,并添加了一个按钮,你可以使用它来获取"快照"。注意选择器只获取当前可见的图像。
肉:
$('#slideshow').cycle({
fx: 'none',
timeout: 1,
continuation: 1,
speed: 'fast',
before: function (curr, next, opts) {
$('#testNum').html("Current slide " + opts.currSlide);
var $img = $("#slideshow img:visible").clone();
$("#test").html('').append($img); }
});
// The button will work after you click fast,slow, or reverse.
// The reason for that is the .cycle function above replaces it
// as fast as you can see it.
$("#btnCopy").on("click",function(){
var $img = $("#slideshow img:visible").clone();
$("#test").html('').append($img);
});
相关文章:
- jQuery:循环一个具有不同超时值的循环
- jQuery循环在特定位置暂停
- 循环中的jQuery循环
- 使用val()在jquery循环中设置html字符串的val
- $.每个jquery循环打印一个“;未定义的“;对于getJSON请求后的每个元素,网格数据都会完美地打印出来
- jQuery循环寻呼机附加较小的图像大小
- 如何优化这个jquery循环的执行时间
- Jquery循环停止按钮
- 如何使用jQuery循环变量名
- Jquery循环洗涤器插件:添加到图像的链接
- 遍历 jQuery:循环遍历子项
- Javascript / JQuery循环访问已发布的ajax数据字符串以为其分配新值
- Jquery 循环一次或在数据数组中显示一次数据
- Jquery 循环与名称 increament.
- jQuery 循环 JSON 结果,对象作为值
- 正在尝试将jquery鼠标滚轮插件插入到jquery循环2中
- jQuery循环遍历每个li并检查一个类
- 使用jQuery循环遍历颜色数组
- 使用jquery循环表行并通过类名访问数据
- 对未知数量的元素执行Jquery循环