如何在不编辑的情况下覆盖插件的几个参数

How can I override few parameter of plugin without editing it

本文关键字:参数 几个 插件 覆盖 编辑 情况下      更新时间:2023-09-26

想要在不编辑的情况下覆盖插件的几个参数。 插件链接 https://www.o2.co.uk/shop/homepage/images/shop15/carousel/js/carousel.jquery.js 我们可以添加另一个脚本来覆盖上面的脚本对象参数,例如 displayTime 到 1000 和 autoStart 到 false。我尝试了 $.extend()。但失败了。我不想在当前插件中进行更改

<script>
(function($,document,undefined) {
$.fn.carousel = function(opts) {
var options = {
   'displayTime': 5000,
   'autoStart': true
};
<----code --->
}
</script>

你可以用你自己的函数替换它:

var oldCarousel = $.fn.carousel; // Need a reference to the original
$.fn.carousel = function(opts) {
  var options = {
    // set your personal defaults here
  };
  if (opts) {
    $.extend(options, opts);
  }
  return oldCarousel.call(this, opts);
};