diff --git a/jquery.placeholder.js b/jquery.placeholder.js index 299fc67..d0a64d4 100644 --- a/jquery.placeholder.js +++ b/jquery.placeholder.js @@ -27,7 +27,7 @@ ]; var setupPlaceholder = function(input, options) { - var i, evt, text, styles, zIndex, marginTop, dy, attrNode; + var i, text, styles, zIndex, marginTop, dy, marginLeft, dx, attrNode; var $input = $(input), $placeholder; try { @@ -76,6 +76,12 @@ if (isNaN(marginTop)) marginTop = 0; $placeholder.css('margin-top', marginTop + dy); + // compensate for x difference caused by absolute / relative difference + dx = $input.offset().left - $placeholder.offset().left; + marginLeft = parseInt($placeholder.css('margin-left')); + if (isNaN(marginLeft)) marginLeft = 0; + $placeholder.css('margin-left', marginLeft + dx); + // event handlers + add to document $placeholder.on('mousedown', function() { if (!$input.is(':enabled')) return;