joaopereirawd / fakeLoader.js

fakeLoader.js is a lightweight jQuery plugin that helps you create an animated spinner with a fullscreen loading mask to simulate the page preloading effect.
MIT License
721 stars 270 forks source link

Any way to trigger via boolean instead of timer? #16

Closed ghost closed 7 years ago

ghost commented 8 years ago

I'm looking for a way to trigger it based on a boolean value.

Sometimes the time taken to execute an action differs, so I'd prefer to be able to set a flag to display whether to display the loader or not.

changyushun commented 8 years ago

jQuery Plugin:

  1. add local var and public method var isStop = false; //console.log(isStop); $.fn.fakeLoader.stop = function () { isStop = true; //console.log('call outside ' + isStop); };
  2. check timeToHide is 0 or not, if 0 mean set interval timer to check 'isStop' value if (settings.timeToHide > 0) { setTimeout(function () { $(el).fadeOut(); }, settings.timeToHide); } else { var timer = setInterval(function () { //console.log(isStop); if (isStop) { $(el).fadeOut(); clearInterval(timer); } }, 200); }

finally HTML code: var loader = $('#fakeLoader'); // show loader.fakeLoader(); // disapear loader.fakeLoader.stop();

ghost commented 7 years ago

Thanks @changyushun !