gpt4 book ai didi

javascript - 动态/连续改变宽度的 div 或 span

转载 作者:行者123 更新时间:2023-11-28 09:25:58 24 4
gpt4 key购买 nike

我有来自 jQuery animate 的示例代码我想让 div 根据计数器、根据时间自动扩展,随着计数器或时间的变化,div 会变宽。我不知道如何使用变量来替换宽度:“70%”

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy for Windows (vers 14 February 2006), see www.w3.org">
<style type="text/css">
div {
background-color:#bca;width:100px;border:1px solid green;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript">
</script>
<title></title>
</head>
<body>
<button id="go">» Run</button>
<div id="block">
Hello!
</div>
<script type="text/javascript">
/* Using multiple unit types within one animation. */
$("#go").click(function(){ $("#block").animate({ width: "70%", opacity: 0.4, marginLeft: "0.6in", fontSize: "3em", borderWidth: "10px" }, 1500 );});
</script>
</body>
</html>

最佳答案

请使用宽度变量的示例代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy for Windows (vers 14 February 2006), see www.w3.org">
<style type="text/css">
div {
background-color:#bca;width:100px;border:1px solid green;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript">
</script>
<title></title>
</head>
<body>
<button id="go">» Run</button>
<div id="block">
Hello!
</div>
<script type="text/javascript">
var someWidth = "70%";
/* Using multiple unit types within one animation. */
$("#go").click(function(){ $("#block").animate({ width: someWidth, opacity: 0.4, marginLeft: "0.6in", fontSize: "3em", borderWidth: "10px" }, 1500 );});
</script>
</body>
</html>

关于javascript - 动态/连续改变宽度的 div 或 span,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14388090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com