Advertisement
Guest User

Untitled

a guest
Apr 18th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.34 KB | None | 0 0
  1. (function($){
  2.     $.fn.extend({
  3.         AddArrow: function(options) {
  4.              var defaults = {
  5.                 ArrowHeight: '32',
  6.                 ArrowWidth: '32',
  7.                 ArrowPath: 'images/arrow.png',
  8.                 Orientation: 'Top',
  9.                 Fade: true,
  10.                 FadeSpeed: 300,
  11.                 MouseOver: true        
  12.             };
  13.            
  14.             var options = $.extend(defaults, options);
  15.          
  16.             return this.each(function() {
  17.                   var o = options;            
  18.                   var pos = $(this).position();
  19.                   var width = $(this).width();
  20.                   var height = $(this).height();
  21.                  
  22.    
  23.                   switch (o.Orientation) {
  24.                     case (o.Orientation = "Top"):
  25.                         $(this).append($('<img>', {
  26.                             src: o.ArrowPath,
  27.                             alt: "Arrow-Top",
  28.                             class: "arrows",
  29.                             style: "height: "+o.ArrowWidth+"px; width: "+o.ArrowHeight+"px; top: "+pos.top+"px; left: "+width / 2 + pos.left+"px; position: absolute; display: none;"
  30.                         }));
  31.                     break;
  32.                     case (o.Orientation = "Right"):
  33.                         $(this).append($('<img>', {
  34.                             src: o.ArrowPath,
  35.                             alt: "Arrow-Top",
  36.                             class: "arrows",
  37.                             style: "height: "+o.ArrowWidth+"px; width: "+o.ArrowHeight+"px; top: "+pos.top + height / 2+"px; left: "+width + pos.left - o.ArrowWidth+"px; position: absolute; display: none;"
  38.                         }));
  39.                     break;
  40.                     case (o.Orientation = "Bottom"):
  41.                         $(this).append($('<img>', {
  42.                             src: o.ArrowPath,
  43.                             alt: "Arrow-Top",
  44.                             class: "arrows",
  45.                             style: "height: "+o.ArrowWidth+"px; width: "+o.ArrowHeight+"px; top: "+pos.top + height - o.ArrowHeight+"px; left: "+width / 2 + pos.left+"px; position: absolute; display: none;"
  46.                         }));
  47.                     break;
  48.                     case (o.Orientation = "Left"):
  49.                         $(this).append($('<img>', {
  50.                             src: o.ArrowPath,
  51.                             alt: "Arrow-Top",
  52.                             class: "arrows",
  53.                             style: "height: "+o.ArrowWidth+"px; width: "+o.ArrowHeight+"px; top: "+pos.top + height / 2+"px; left: "+pos.left+"px; position: absolute; display: none;"
  54.                         }));
  55.                     break;
  56.                   }
  57.                   if(o.Fade)
  58.                   {        
  59.                         $(this).hover(function() {
  60.                             $(".arrows").fadeIn(o.FadeSpeed);
  61.                         },
  62.                         function() {
  63.                             $(".arrows").fadeOut(o.FadeSpeed);
  64.                         });
  65.                   }
  66.             });
  67.         }
  68.     });
  69. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement