add functions to javascript / JQuery object -
$(".box").each(function(){ $(this).distance_left = function() { return $(this).offset().left - $(this).parent().offset().left; } $(this).distance_top = function() { return $(this).offset().top - $(this).parent().offset().top; } });
when call distance_left or distance_top on .box object, box.distance_left not function
. why?
you need extend prototype:
$.fn.distance_left = function() { return -1; };
and can use on jquery objects:
$('#myid').distance_left(); // -1
anyway particually case can use
$(this).position().left; $(this).position().top;
Comments
Post a Comment