jQuery Effects ...LOGIN

jQuery Effects - Hide and Show

hide() and show()

With jQuery, you can use the hide() and show() methods to hide and show HTML elements:

Syntax:

$(selector).hide(speed,callback);

$(selector).show(speed,callback);

The optional speed parameter specifies hiding / Display speed, which can take the following values: "slow", "fast" or milliseconds.

The optional callback parameter is the name of the function to be executed after hiding or displaying is completed.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide(1000);
  });
});
</script>
</head>
<body>
<button>隐藏</button>
<p>这是第一个</p>
<p>这是第二个</p>
</body>
</html>

jQuery toggle()

With jQuery, you can use the toggle() method to toggle the hide() and show() methods.

Show hidden elements and hide displayed elements:

Syntax:

$(selector).toggle(speed,callback);

The optional speed parameter specifies the speed of hiding/showing, which can take the following values: "slow", "fast" or milliseconds.

The optional callback parameter is the name of the function executed after the toggle() method is completed.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").toggle();
  });
});
</script>
</head>
<body>
  <button>隐藏/显示</button>
  <p>点击一次隐藏</p>
  <p>再点击一次显示</p>
</body>
</html>


Next Section
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <style type="text/css"> .big{ font-size:30px; color:#FF0000;} </style> </head> <body> <script> $(function(){ $('#click_event').click(function(){ $('#click_event').html(''); if($('#hidden_enent').is(':hidden')) { $('#hidden_enent').show(); $('#click_event').html('隐藏'); } else { $('#hidden_enent').hide(); $('#click_event').html('显示'); } }) }) </script> <div id="click_event" style="cursor:pointer">隐藏</div> <div id="hidden_enent">测试隐藏</div> </body> </html>
submitReset Code
ChapterCourseware