如何获得jquery的最后状态

时间:2011-10-02 19:25:28

标签: jquery

您好我正在使用http://www.gmarwaha.com/jquery/jcarousellite/中的jquery图像滑块。这是完美的,但在回发后滑块从0开始。如何记住回发后的最后状态?这是现场演示http://sampath.ind.in

$(document).ready(function () {
$("#slidebox").jCarouselLite({
    vertical: false,
    hoverPause: true,
    btnPrev: ".previous",
    btnNext: ".next",
    visible: 3,
    circular: false,
    start: 0,
    scroll: 1,
    speed: 300
});

});

1 个答案:

答案 0 :(得分:0)

您可以使用afterEnd回调将当前状态存储在Cookie或本地存储中,如果存在此密钥,则从那里开始。

这应该设置一个cookie(lastPosition),以后可以使用:

$(...).jCarouselLite({
  ...
  afterEnd:function(e){$.cookie('lastPosition', e.first().index());}
  ...
});

要从预定位置开始,您可以执行以下操作:

$(...).jCarouselLite({
  ...
  start: parseInt($.cookie('lastPosition'),10) || 0
  ...
});

要设置/检索Cookie,您可以使用此库:https://github.com/carhartl/jquery-cookie。这不是经过测试的代码,但它应该给你一个基本的想法。