A jQuery plugin that dynamically points one element at another.
Download
<script src="js/jquery.min.js"></script>
<!-- using jQuery UI draggable -->
<script src="js/jquery-ui.min.js"></script>
<script src="js/jquery.pointy.js"></script>
<script>
$(function(){
// $pointer points at $pointy
var $pointer = $('.label.pointer'),
// initialize pointy (showing all options; but not all defaults)
$pointy = $('.repo-name').pointy({
pointer : $pointer,
arrowWidth : 10, // width of pointer base
borderWidth : 1, // pointer stroke width
flipAngle : 45, // angle @ which to flip pointer to a closer side
defaultClass : '', // additional class name added to the pointer & the arrow (canvas)
activeClass : 'pointy-active', // class added to base & pointer on updating
// optional; if not set, plugin will attempt to match the base color
borderColor : null,
backgroundColor : null,
// tweaks
useOffset : null
});
// Using jQuery UI draggable (any draggable code will work)
$label.draggable({
containment : '.top',
drag : function() {
$pointy.trigger('pointy-update');
}
});
});
</script>
pointer
jQuery objectnullarrowWidth
Number20borderWidth
Number1defaultClass
String'' (empty string)activeClass
String'pointy-active'flipAngle
Number45borderColor
null, then pointy matches the base (draggable element) border color.StringnullbackgroundColor
null, then pointy matches the base (draggable element) background color.StringnulluseOffset
offset() or postion() to determine the elements coordinates.null, then Pointy looks for a set margin on the pointee element, if there isn't one, then Pointy uses the element's offset(), otherwise the position() is used.true or false, whichever one works, if Pointy looks like it's having a seizure.BooleannullThe pointy arrow needs to be updated after the pointer (draggable) element is moved
Pointy data is stored in the pointee (stationary) element, so use this method to reposition & redraw the arrow:// $('.pointy') is the pointee (stationary) element
$('.pointy').trigger('pointy-update');
If the pointee (stationary) element moves, or was resized then you'll need to refresh pointy to update the internal constants.
Refreshing pointy includes an update, so you only need to trigger the refresh method:// $('.pointy') is the pointee (stationary) element
$('.pointy').trigger('pointy-refresh');
or you could simply trigger a window resize:
$(window).resize();
// $('.pointy') is the pointee (stationary) element
$('.pointy').trigger('pointy-hide');
// $('.pointy') is the pointee (stationary) element
$('.pointy').trigger('pointy-show');
// $('.pointy') is the pointee (stationary) element
$('.pointy').trigger('pointy-destroy');