jwAnnounce - jQuery Plugin


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. (function($) {
  2.  
  3. $.fn.jwNotice = function(options) {
  4.  
  5. var options = $.extend({
  6. className : 'notice',
  7. text : null,
  8. siteWidth : null
  9. }, options);
  10.  
  11. return this.each(function() {
  12.  
  13. $(this).prepend('<div class="' + options.className + '" />');
  14.  
  15. var $announceDiv = $('.' + options.className);
  16.  
  17. $announceDiv
  18. .append('<div>' + options.text + '</div>')
  19. .children('> div')
  20. .css({
  21. 'width' : options.siteWidth,
  22. 'margin' : 'auto'
  23. })
  24. .end()
  25. .prepend('<span class="close">X</span>')
  26. .children('.close')
  27. .css({
  28. 'position' : 'absolute',
  29. 'cursor' : 'pointer',
  30. 'display' : 'none'
  31. })
  32. .end()
  33.  
  34. .hover(function() {
  35. // over
  36. $(this)
  37. .children('span.close')
  38. .show()
  39. .click(function() {
  40. $announceDiv.slideUp(250, function() {
  41. $(this).remove();
  42. });
  43. });
  44.  
  45. }, function() {
  46. // out
  47. $('.close').hide();
  48. });
  49.  
  50. }); // end each
  51.  
  52. }
  53.  
  54. })(jQuery);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.