我有jQuery animate 的示例代碼,我想根據時間自動根據計數器擴展div,因爲計數器或時間變化div變寬。我無法弄清楚如何使用一個變量來代替寬度:「70%」動態/連續變化寬度的div或跨度
<!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>
看起來你是一個良好的開端。您是否有任何研究或其他代碼來證明您嘗試尋找您正在尋找的解決方案? –