jQuery.headroom.js 851 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. (function($) {
  2. if(!$) {
  3. return;
  4. }
  5. ////////////
  6. // Plugin //
  7. ////////////
  8. $.fn.headroom = function(option) {
  9. return this.each(function() {
  10. var $this = $(this),
  11. data = $this.data('headroom'),
  12. options = typeof option === 'object' && option;
  13. options = $.extend(true, {}, Headroom.options, options);
  14. if (!data) {
  15. data = new Headroom(this, options);
  16. data.init();
  17. $this.data('headroom', data);
  18. }
  19. if (typeof option === 'string') {
  20. data[option]();
  21. if(option === 'destroy'){
  22. $this.removeData('headroom');
  23. }
  24. }
  25. });
  26. };
  27. //////////////
  28. // Data API //
  29. //////////////
  30. $('[data-headroom]').each(function() {
  31. var $this = $(this);
  32. $this.headroom($this.data());
  33. });
  34. }(window.Zepto || window.jQuery));