2011-05-21 28 views
0

我想向我的div控件顯示一個動畫。


當頁面是加載div應該隱藏,當用戶點擊一個按鈕div應該出現一些動畫我想在我的div控件上顯示一個滑動動畫,這應該發生在單擊按鈕時。
我必須在jQuery中做到這一點。div應該與動畫一起出現

+0

@ 741535:你能解釋一下嗎? – TimSo 2011-05-21 19:35:46

回答

1
$(document).ready(function(){ 
    $("#btn").click(function(){ 
    $(".divClass").slideToggle("slow"); 

    }); 
}); 

其他選項slideDown, slideUp, slideToggle,fadeIn, fadeOut, fadeTo
一個完整的例子是遵循

<html> 
<head> 

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#btn").click(function(){ 
    $(".divClass").slideToggle("slow"); 

    }); 
}); 
</script> 

<style type="text/css"> 
.divClass 
{ 
margin:0px; 
padding:5px; 
text-align:center; 
background:#e5eecc; 
border:solid 1px #c3c3c3; 
height:120px; 
display:none; 
} 
</style> 
</head> 

<body> 

<div class="divClass"> 
<p>This is a sample JQuery Animation</p> 
<p>Your text or control goes here...Your text or control goes here....Your text or control goes here</p> 
</div> 

<input id="btn" type="button" value="Show Div" /> 

</body> 
</html>