notify.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (function ($) {
  2. $.fn.extend({
  3. notify: function (options) {
  4. var settings = $.extend({ type: 'sticky', speed: 500, onDemandButtonHeight: 35 }, options);
  5. return this.each(function () {
  6. var wrapper = $(this);
  7. var ondemandBtn = $('.ondemand-button');
  8. var dh = -35;
  9. var w = wrapper.outerWidth() - ondemandBtn.outerWidth();
  10. ondemandBtn.css('left', w).css('margin-top', dh + "px" );
  11. var h = -wrapper.outerHeight();
  12. wrapper.addClass(settings.type).css('margin-top', h).addClass('visible').removeClass('hide');
  13. if (settings.type != 'ondemand') {
  14. wrapper.stop(true, false).animate({ marginTop: 0 }, settings.speed);
  15. }
  16. else {
  17. ondemandBtn.stop(true, false).animate({ marginTop: 0 }, settings.speed);
  18. }
  19. var closeBtn = $('.close', wrapper);
  20. closeBtn.click(function () {
  21. if (settings.type == 'ondemand') {
  22. wrapper.stop(true, false).animate({ marginTop: h }, settings.speed, function () {
  23. wrapper.removeClass('visible').addClass('hide');
  24. ondemandBtn.stop(true, false).animate({ marginTop: 0 }, settings.speed);
  25. });
  26. }
  27. else {
  28. wrapper.stop(true, false).animate({ marginTop: h }, settings.speed, function () {
  29. wrapper.removeClass('visible').addClass('hide');
  30. });
  31. }
  32. });
  33. if (settings.type == 'floated') {
  34. $(document).scroll(function (e) {
  35. wrapper.stop(true, false).animate({ top: $(document).scrollTop() }, settings.speed);
  36. }).resize(function (e) {
  37. wrapper.stop(true, false).animate({ top: $(document).scrollTop() }, settings.speed);
  38. });
  39. }
  40. else if (settings.type == 'ondemand') {
  41. ondemandBtn.click(function () {
  42. $(this).animate({ marginTop: dh }, settings.speed, function () {
  43. wrapper.removeClass('hide').addClass('visible').animate({ marginTop: 0 }, settings.speed, function () {
  44. });
  45. })
  46. });
  47. }
  48. });
  49. }
  50. });
  51. })(jQuery);