49 jQuery-使用show()與hide()方法動畫顯示和隱藏圖片
阿新 • • 發佈:2019-01-03
1.效果圖
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>