简体   繁体   中英

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

I have the following code: and I want to call

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

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"?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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