简体   繁体   English

如何在jquery的另一个函数中嵌入函数调用?

[英]How can I embed a function call inside another function in jquery?

I have the following code: and I want to call 我有以下代码:我想打电话

preloadfunction() preloadfunction()

  (function ($) {
 $.fn.waterwheelCarousel = function (options) {
 options = $.extend({}, $.fn.waterwheelCarousel.defaults, options || {});

    return $(this).each(function () {
 var data = {
        itemsContainer:         $(this).find(".carousel-images"),
        totalItems:             $(this).find(".carousel-images img").length,
        containerWidth:         $(this).width(),
        containerHeight:        $(this).height(),
        currentCenterItem:      null,
        items:                  [],
        itemDistances:          [],
        waveDistances:          [],
        itemWidths:             [],
        itemHeights:            [],
        itemOpacities:          [],
        carouselRotationsLeft:  0,
        currentlyMoving:        false,
        itemsAnimating:         0,
        currentSpeed:           options.speed,
        intervalTimer:          null
      };

      // Setup the carousel
      beforeLoaded();
      // Preload the images. Once they are preloaded, the passed in function
      // will be called and the carousel will be setup
      preload(function () {
        setupDistanceArrays();
        setupCarousel();
        setupStarterRotation();
      });

I have tried : 我努力了 :

waterwheelCarousel().preloadfunction() and it's give me undefined method waterwheelCarousel().preloadfunction()它给了我未定义的方法

also I have tried : 我也试过了:

var t = $("#waterwheelcarouseldefault").waterwheelCarousel(); 
t.preloadfunction();

with no luck any one knows how to call this function? 运气不好,有人知道如何调用此函数吗?

Isn't the function called "preload", and not "preloadfunction"? 函数不是叫做“ preload”,不是“ preloadfunction”吗?

Have you tried 你有没有尝试过

waterwheelCarousel().preload();

You could also create an object of your structure this way the code will get more readable. 您还可以通过这种方式创建结构对象,从而使代码更具可读性。 for example: 例如:

var app = 
{
      // Setup the carousel
      beforeLoaded : beforeLoaded(),
      preload: function () {
        setupDistanceArrays();
        setupCarousel();
        setupStarterRotation();
      }

 };

this way you can access your function by typing app.preload(); 这样,您可以通过键入app.preload();来访问函数app.preload();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM