87,984
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery toggle</title>
<style>
.test{height: 200px; width: 50px; background-color: red; display: none;}
</style>
</head>
<body>
<a href="javascript:;">Trigger</a>
<div class='test'></div>
<script type="text/javascript" src='http://libs.baidu.com/jquery/1.11.1/jquery.min.js'></script>
<script type="text/javascript">
$(document).ready(function() {
$('a').click(function() {
$('.test').toggle('slide');
});
});
</script>
</body>
</html>
[/quote]
发现是什么问题了。再次点击按钮的时候宽度无法变回去,所以不能回缩
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery toggle</title>
<style>
.test{height: 200px; width: 50px; background-color: red; display: none;}
</style>
</head>
<body>
<a href="javascript:;">Trigger</a>
<div class='test'></div>
<script type="text/javascript" src='http://libs.baidu.com/jquery/1.11.1/jquery.min.js'></script>
<script type="text/javascript">
$(document).ready(function() {
$('a').click(function() {
$('.test').toggle('slide');
});
});
</script>
</body>
</html>
<script type="text/javascript" src='http://libs.baidu.com/jquery/1.11.1/jquery.min.js'></script>
[/quote]
我试了一下,能展开,不能收缩,而且展开不是平稳滑动的
<script type="text/javascript" src='http://libs.baidu.com/jquery/1.11.1/jquery.min.js'></script>
$(function() {
$('#Admin').click(function(){
$("#modmenu").toggle(function(){
$(this).animate({marginTop: -20},500).parent('div').animate({height: 0},520);
},function(){
$(this).animate({marginTop: 0},500).parent('div').animate({height: 20},520);
})
});
$("#modmenu").click(function() {
$(this).animate({marginTop: -20},520).parent('div').animate({height: 0},500);
});
})
$("#按钮id").click(function(){
$("#modmenu").show();
});
$("#modmenu").click(function(){
$(this).show();
});