gpt4 book ai didi

javascript - toggleClass 问题的 jQuery 持续时间

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

我试图在 1 秒内更改 div 元素的样式类并产生一些效果。这是我的代码。当我执行这个示例样式时,立即切换,没有效果和超时。我做错了什么?

<html>
<head>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript">
$().ready(function() {
$("#changeStyle").click(function() {
$("#divka").toggleClass("a1","slow");
return false;
});
});
</script>
<link rel="stylesheet" href="style.css" type="text/css"/>


</head>
<body>
<div id="divka"></div>
<input type="button" id="changeStyle" value="change style"/>
</body>



.a1 {
border: 1px solid black;
background-color:#eee;
width:200px;
height:400px;
}

最佳答案

toggleClass 不为样式属性设置动画,您必须使用 JQuery 的动画方法。

$("#divka").animate({
borderWidth: "1px",
borderColor: "#000",
borderStyle: "solid",
backgroundColor:"#eee",
width:"200px",
height:"400px",
}, 500);

关于javascript - toggleClass 问题的 jQuery 持续时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6817233/

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