刷新幻灯片 [英] Refresh slidejs

查看:108
本文介绍了刷新幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://www.slidesjs.com/ 中的幻灯片,我想刷新图像列表,因为我需要动态添加和删除图像。

I'm using slidejs from http://www.slidesjs.com/ and I wanted to refresh the list of images, because I need to add and remove images on the fly.

有没有办法做到这一点?我曾尝试使用delete $ .fn.pluginName但没有运气。

Is there any way to do this? I've tried to use the delete $.fn.pluginName but no luck.

谢谢

推荐答案

我最近有同样的问题并设法通过更改插件来解决它。

I recently had the same issue and manage to solve it by changing the plugin.

这是我的解决方案:

之前添加以下这些行:Plugin.prototype.init = function(){

Plugin.prototype.refresh = function (number){
    var $element=$(this.element);
    var _this = this;
    this.data = $.data(this);
    $(this.element).find(".slidesjs-pagination-item").remove();
    $.data(this, "total", $(".slidesjs-control", $element).children().not(".slidesjs-navigation", $element).length);
    $.each($(".slidesjs-control", $element).children(), function(i) {
        var $slide;
        $slide = $(this);
        return $slide.attr("slidesjs-index", i);
      });
    $.each($(".slidesjs-control", $element).children(), function(i) {
        var $slide;
        $slide = $(this);
        return $slide.attr("slidesjs-index", i);
      });
      if (this.data.touch) {
        $(".slidesjs-control", $element).on("touchstart", function(e) {
          return _this._touchstart(e);
        });
        $(".slidesjs-control", $element).on("touchmove", function(e) {
          return _this._touchmove(e);
        });
        $(".slidesjs-control", $element).on("touchend", function(e) {
          return _this._touchend(e);
        });
      }
      $element.fadeIn(0);
      this.update();
      if (this.data.touch) {
        this._setuptouch();
      }
      $(".slidesjs-control", $element).children(":eq(" + this.data.current + ")").eq(0).fadeIn(0, function() {
        return $(this).css({
          zIndex: 10
        });
      });
      if (this.options.navigation.active) {
        prevButton = $("<a>", {
          "class": "slidesjs-previous slidesjs-navigation",
          href: "#",
          title: "Previous",
          text: "Previous"
        }).appendTo($element);
        nextButton = $("<a>", {
          "class": "slidesjs-next slidesjs-navigation",
          href: "#",
          title: "Next",
          text: "Next"
        }).appendTo($element);
      }
      $(".slidesjs-next", $element).click(function(e) {
        e.preventDefault();
        _this.stop(true);
        return _this.next(_this.options.navigation.effect);
      });
      $(".slidesjs-previous", $element).click(function(e) {
        e.preventDefault();
        _this.stop(true);
        return _this.previous(_this.options.navigation.effect);
      });
      if (this.options.play.active) {
        playButton = $("<a>", {
          "class": "slidesjs-play slidesjs-navigation",
          href: "#",
          title: "Play",
          text: "Play"
        }).appendTo($element);
        stopButton = $("<a>", {
          "class": "slidesjs-stop slidesjs-navigation",
          href: "#",
          title: "Stop",
          text: "Stop"
        }).appendTo($element);
        playButton.click(function(e) {
          e.preventDefault();
          return _this.play(true);
        });
        stopButton.click(function(e) {
          e.preventDefault();
          return _this.stop(true);
        });
        if (this.options.play.swap) {
          stopButton.css({
            display: "none"
          });
        }
      }
      if (this.options.pagination.active) {
        pagination = $("<ul>", {
          "class": "slidesjs-pagination"
        }).appendTo($element);
        $.each(new Array(this.data.total), function(i) {
          var paginationItem, paginationLink;
          paginationItem = $("<li>", {
            "class": "slidesjs-pagination-item"
          }).appendTo(pagination);
          paginationLink = $("<a>", {
            href: "#",
            "data-slidesjs-item": i,
            html: i + 1
          }).appendTo(paginationItem);
          return paginationLink.click(function(e) {
            e.preventDefault();
            _this.stop(true);
            return _this.goto(($(e.currentTarget).attr("data-slidesjs-item") * 1) + 1);
          });
        });
      }
      $(window).bind("resize", function() {
        return _this.update();
      });
      this._setActive();
    if (number){            
        this.goto(number+1);
    } else {
        this.goto(0);
    }

};

然后,更改的内容返回$ .fn [pluginName] = function (options,the_args){ to this:

Then, change the content of return $.fn[pluginName] = function(options,the_args) { to this:

return $.fn[pluginName] = function(options,the_args) {
    var the_return=this.each(function() {
        if (!$.data(this, "plugin_" + pluginName)) {
          return $.data(this, "plugin_" + pluginName, new Plugin(this, options));
        }
    });
    if (typeof options=="string"){
        var element=this.get(0);
        if (arguments.length>1){
            var the_args=Array.prototype.slice.call(arguments);;
            the_args.splice(0,1);
            var plugin=$.data(element, "plugin_" + pluginName);
            return plugin[options].apply(plugin,the_args);
        } else {
            return $.data(element, "plugin_" + pluginName)[options]();
        }
    }
  return the_return;
};

这样,您可以调用插件的其他功能,如 goto

This way, you could call other functions of the plugin like goto.

在代码中,你只需要像这样调用刷新函数:

In the code, you just need to call the refresh function like this:

$("#id_of_container").slidesjs("refresh");

或者,如果你想刷新并跳转到另一张幻灯片,请按以下方式调用:

or, if you want to refresh and jump to another slide, call it like this:

$("#id_of_container").slidesjs("refresh",number_of_slide);

其中 number_of_slide 是一个int数字,从0;

where number_of_slide is an int number starting at 0;

这篇关于刷新幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆