admin管理员组

文章数量:1357121

I want to zoom/unzoom a text with animate. The problem is that the text is absolutely positioned inside a relative div and when I animate the font-size the text expands only to the right and bottom. I want it to expand/retract to all sides equally.

Prepared example:

I want to zoom/unzoom a text with animate. The problem is that the text is absolutely positioned inside a relative div and when I animate the font-size the text expands only to the right and bottom. I want it to expand/retract to all sides equally.

Prepared example: http://jsbin./wele/48103/edit

Share Improve this question asked Nov 13, 2012 at 16:03 Eike CochuEike Cochu 3,4377 gold badges36 silver badges58 bronze badges 3
  • Does the text have to remain relatively positioned? – Luke Commented Nov 13, 2012 at 16:07
  • You need to animate top: and left: along with the resize. – Diodeus - James MacFarlane Commented Nov 13, 2012 at 16:07
  • do u need the animation? coz otherwise u could just use plain CSS to increase font sizes on hover in and out – Sajjan Sarkar Commented Nov 13, 2012 at 16:08
Add a ment  | 

2 Answers 2

Reset to default 5

Animate using the CSS transition property:

.zoom {
  display: inline-block; /* this is needed for inline elements */
  transition: transform 0.3s ease-in-out;
}

.zoom:hover {
  transform: scale(1.4);
}
<a class="zoom" href='#'>Hover me!</a>

The align in horizontal center is easy. Just add text-align: center and it will work. But if you want to align it in middle, you need to use display: table, because "only" td is "allowed" to set vertical-align: middle. So you have to build a div-table layout around: http://jsbin./wele/48145/edit

本文标签: javascriptJQuery zoom text on hoverStack Overflow