toggleClass问题的jQuery持续时间 [英] jQuery duration for toggleClass issue

查看:209
本文介绍了toggleClass问题的jQuery持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to change style class of div element during 1 second with some effect. This is my code. When I execute this example style switches immediately without effects and timeouts. What I'm doing wrong?

<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的动画方法。

toggleClass do not animate the style attributes you have to use animate method of JQuery.

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

这篇关于toggleClass问题的jQuery持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆