Solved

jquery expand and align

Posted on 2012-03-31
2
276 Views
Last Modified: 2012-04-08
Hello Experts,

I really need a help from an expert here!

I have a photo. On that photo i placed a circles with numbers using css absolute positions.
When the user mouse-over a circle the circle expands around 1.5 times (e.g. the initial size of a circle is 16px on 16px and it grows to 24px on 24px.

The problem.....

The number on the circles are horizontally center-aligned using the css text-align:center.
When the circle expands the numbers should also be vertically align.

I tried varied options using padding-top and or increasing line-height but nothing seem to work smoothly.

Here is just a part of the script i am using to expand the circle. If you have a good idea i would be thankful!

  var $position;
  $('.map-bullet').mouseenter(function(){
    $position = $(this).position();

    $(this).stop().animate({
       width: 24,
       height: 24,
       top: ($position.top - (8/2)), left: ($position.left -(8/2))}, 100);
	
}).mouseleave(function() {

   $(this).stop().animate({
        width: 16,
       height: 16,
       top: $position.top, left: $position.left}, 100);

Open in new window

0
Comment
Question by:Refael
2 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 37792310
You were on the right track with line-height, however, as the circle expands, you must also increase the line-height then set it back to 16 on mouseleave.

var $position;
    $('.map-bullet').mouseenter(function(){
        $position = $(this).position();

        $(this).stop().animate({
            width: 24,
            height: 24,
            top: ($position.top - (8/2)), left: ($position.left -(8/2)), 'line-height':'24px'}, 100);
      
    }).mouseleave(function() {

        $(this).stop().animate({
            width: 16,
            height: 16,
            top: $position.top, left: $position.left, 'line-height':'16px'}, 100);
    });
0
 

Author Closing Comment

by:Refael
ID: 37821871
Thank you!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java script read and write file - save as location 8 44
How to convert from xls to xlsx using java 7 39
Jquery 10 20
CSS: Making Pure CSS read more boxes thinner 5 31
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question