我想为一个 div 设置动画,使上半部分(高度:50 像素)的宽度为 100 像素,下半部分(高度:200 像素)的宽度为 200 像素。这可能吗?
有关我希望在一个 div 中设置动画的最终结果示例,请参见 jsfiddle。
一些来自 JsFiddle 的 CSS 用于我的示例图片,因为 StackOverflow 给我带来了麻烦,因为只有一个 jsFiddle 链接:
#a{
background-color:blue;
height:50px;
width:100px;
}
#b{
background-color:blue;
height:200px;
width:200px;
}
这可能吗? 如果是,我将如何着手这样做?
最佳答案
我不确定希望此链接对您有所帮助。 http://css-tricks.com/snippets/jquery/animate-heightwidth-to-auto/
还有这个:
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color:#bca;
width:200px;
height:1.1em;
text-align:center;
border:2px solid green;
margin:3px;
font-size:14px;
}
button {
font-size:14px;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<button id="go1">» Animate Block1</button>
<button id="go2">» Animate Block2</button>
<button id="go3">» Animate Both</button>
<button id="go4">» Reset</button>
<div id="block1">Block1</div>
<div id="block2">Block2</div>
<script>
$( "#go1" ).click(function(){
$( "#block1" ).animate( { width: "90%" }, { queue: false, duration: 3000 })
.animate({ fontSize: "24px" }, 1500 )
.animate({ borderRightWidth: "15px" }, 1500 );
});
$( "#go2" ).click(function(){
$( "#block2" ).animate({ width: "90%" }, 1000 )
.animate({ fontSize: "24px" }, 1000 )
.animate({ borderLeftWidth: "15px" }, 1000 );
});
$( "#go3" ).click(function(){
$( "#go1" ).add( "#go2" ).click();
});
$( "#go4" ).click(function(){
$( "div" ).css({ width: "", fontSize: "", borderWidth: "" });
});
</script>
</body>
</html>
关于jquery - 是否可以仅从指定高度设置动画和更改 div 的宽度,而其余部分保持原样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17854494/