使Javascript / JQuery Slidedown菜单开始隐藏而不是显示

时间:2015-02-21 00:30:13

标签: javascript jquery html

我想知道你们是否可以帮助我使用Slidingown菜单。它从内容显示开始,我想让它开始隐藏,所以当你点击按钮它会显示它不会开始显示内容。 继承我的代码:



var test = $('#test'),
    toggle = $('#toggle');


toggle.click(function() {
    test.slideToggle(1000, function() {
    });
});

<!DOCTYPE html>    
<head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>PASSWORD PROTECTION</title>
         <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>
    <script type='text/javascript' src='main.js'></script>
        <meta name="description" content="An interactive getting started guide for Brackets.">
        <link rel="stylesheet" href="style.css">
</head>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Down Menu Click</title>



</head>
<body></body>
    
<button id="toggle">Login</button></p>

<div id="test">
    	<div class="slideTogglebox">
<h2>Login</h2>
<form id="form" onsubmit="return false;">
<input type="password" id="values" />
<input type="submit" onclick="lg();" />
<input type="reset" onclick="location.reload();" />    
	</div>
<nil></nil>
</body>
</html>
        



</script>






  
    
    
    
    </body>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

尝试添加     显示:无; 在你的style.css中#test。

或者,您也可以将其添加到标记中:

<div id="test" style="display:none">

见下文:

&#13;
&#13;
var test = $('#test'),
    toggle = $('#toggle');


toggle.click(function() {
    test.slideToggle(1000, function() {
    });
});
&#13;
<!DOCTYPE html>    
<head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>PASSWORD PROTECTION</title>
         <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>
    <script type='text/javascript' src='main.js'></script>
        <meta name="description" content="An interactive getting started guide for Brackets.">
        <link rel="stylesheet" href="style.css">
</head>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Down Menu Click</title>



</head>
<body></body>
    
<button id="toggle">Login</button></p>

<div id="test" style="display:none">
    	<div class="slideTogglebox" >
<h2>Login</h2>
<form id="form" onsubmit="return false;">
<input type="password" id="values" />
<input type="submit" onclick="lg();" />
<input type="reset" onclick="location.reload();" />    
	</div>
<nil></nil>
</body>
</html>
        



</script>






  
    
    
    
    </body>
&#13;
&#13;
&#13;