开发者

jQuery animate()

开发者 https://www.devze.com 2023-01-18 17:17 出处:网络
function toggle() { $(\"#Layer4\").animate( { width:\"20%\"}, 1000 ); $(\"#Layer6\").animate( { width:\"20%\"}, 1000 );
function toggle() 
    {
    $("#Layer4").animate( { width:"20%"}, 1000 );
    $("#Layer6").animate( { width:"20%"}, 1000 );
    }

Now what happens is that Layer4 and Layer6 witness some animation, but interestingly the height changes and not the width.

Also, after a second, the original dimensions are restored.

Why is this happening ?

--

<body onload="open()">
  <开发者_开发问答;div id="Layer4">
    <img src="friend-line.jpg" width="243" height="380" />
  </div>
  <div id="Layer5" onClick="toggle()">
    <img src="toggle_in.jpg" width="7" height="50" />
  </div>
  <div id="Layer6"></div>
</body>


I don't believe you'll have consistent results using %. Try using pixels instead. If you must use % make sure that you don't have a surrounding div which the width is also set in %. My guess is that that is the case.


You can't reduce the size of the div by less than the img tag. If you want that behavior you'll need to replace the img tag with a background-image style.


Try resizing images instead of their containers...

$('#Layer4 img').animate( { width:'20%'}, 1000 );
$('#Layer6 img').animate( { width:'20%'}, 1000 );

And even better, use pixels instead of percents, as already suggested.

0

精彩评论

暂无评论...
验证码 换一张
取 消