天天看點

49 jQuery-使用show()與hide()方法動畫顯示和隐藏圖檔

1.效果圖

49 jQuery-使用show()與hide()方法動畫顯示和隐藏圖檔

2.HTML代碼

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>49 jQuery-使用show()與hide()方法動畫顯示和隐藏圖檔</title>
      <style type="text/css">
        body{font-size:13px}
		img{display: none;cursor: pointer;width: 60px;height: 60px;}
	  </style>
</head>
<body>
 	  <a style="cursor: pointer;">顯示</a>
      <img src="../img/pig.jpg" />
              
<script src="../jquery.min.js"></script>
<script type="text/javascript">
	$(function(){
		//顯示連結點選事件
		$("a").click(function(){
			//顯示完成時執行的函數
			$("img").show(3000, function(){
				$(this).css("border", "solid 1px #ccc");
			})
			$(this).hide(3000);
		})
		//顯示圖檔的點選事件
		$("img").click(function(){
			//動畫效果隐藏
			$(this).hide(3000);
			$("a").show(3000);
		})
	})
</script>
</body>
</html>