On Jun 6, 6:36 pm, Evan <otio...@gmail.com> wrote:
> Hi there!
>
> I'm trying to:
>
> 1). Get the number of pixels from the left side of the hovered-element
> that the mouse cursor is located, and
> 2). Set *part* of a CSS attribute to this value
>
> I've been searching, but I can't find the answer to either of these.
> Does anyone know if they are possible? I apologize in advance if this
> is very basic, and I'm being stupid. I would really, really appreciate
> any guidance anyone could give.
>
> Thank you in advance for your help!

Get the mouse cursor position from the event object (http://
docs.jquery.com/Events/jQuery.Event#event.pageX.2FY) and the element
position with offset() (http://docs.jquery.com/CSS/offset):

$('#example').mouseover(function(e){
   var distance = e.pageX - $(this).offset().left;
   $(this).text( distance );
});

Are you having trouble to set the css value also? Would be something
along these lines:

$(this).css({
   fontSize: (distance/10)+'px';
});

--
ricardo

Reply via email to