juqery 点击显示点击隐藏,slideDown slideUp slideToggle

Posted on 2015-06-20 22:43  小蕊同学  阅读(801)  评论(0编辑  收藏  举报
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>webrx-title</title>
  6. <script src="js/jquery-1.11.2.min.js"></script>
  7. <style>
  8. #ad{
  9. width:200px;
  10. height:300px;
  11. background-color:green;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <input type="button" value="slideDown" onClick="$('#ad').slideDown('fast')" >
  17. <input type="button" value="slideUp" onClick="$('#ad').slideUp('fast')">
  18. <input type="button" value="slideToggle" onClick="$('#ad').slideToggle('fast')">
  19. <div id="ad"></div>
  20. </body>
  21. </html>
注意引入的jquery一定要正确
slideToggle   点击关闭再点展开
slideUp        点击合上
slideDown      点击展开

mybtn 的控制点击显示点击隐藏
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>webrx-title</title>
  6. <script src="js/jquery-1.11.2.min.js"></script>
  7. <style>
  8. #ad{
  9. width:200px;
  10. height:300px;
  11. background-color:green;
  12. }
  13. </style>
  14. <script>
  15. $(document).ready(function(e) {
  16. $('input[value=mybtn]').click(function(){
  17. var o=$('#ad');
  18. o.is(':hidden') ? o.slideDown('fast') : o.slideUp('slow');
  19. });
  20. });
  21. </script>
  22. </head>
  23. <body>
  24. <input type="button" value="mybtn">
  25. <div id="ad"></div>
  26. </body>
  27. </html>
fadein fadeout 控制显示隐藏
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>webrx-title</title>
  6. <script src="js/jquery-1.11.2.min.js"></script>
  7. <style>
  8. #ad{
  9. width:200px;
  10. height:300px;
  11. background-color:green;
  12. }
  13. </style>
  14. <script>
  15. $(document).ready(function(e) {
  16. $('input[value=mybtn]').click(function(){
  17. var o=$('#ad');
  18. //(o.is(':hidden') ? o.slideDown('slow') : o.slideUp('slow') )
  19. (o.is(':hidden') ? o.fadeIn('slow') : o.fadeOut('slow') )
  20. });
  21. });
  22. </script>
  23. </head>
  24. <body>
  25. <input type="button" value="fadeIn" onClick="$('#ad').fadeIn('fast')" >
  26. <input type="button" value="fadeOut" onClick="$('#ad').fadeOut('fast')">
  27. <input type="button" value="fadeTo" onClick="$('#ad').fadeToggle('fast')">
  28. <input type="button" value="mybtn">
  29. <div id="ad"></div>
  30. </body>
  31. </html>
注意slideUp和fadeIn
显示和隐藏的效果不同






Copyright © 2024 小蕊同学
Powered by .NET 9.0 on Kubernetes