JQuery's show and hide methods compare to CSS's hidden styles

  • 2020-03-26 21:28:31
  • OfStack

The difference between display:none and visible:hidden

Display :none and visible:hidden can both hide an element on a web page, but there are differences:

Display :none - no physical space is reserved for a hidden object, meaning that the object disappears completely from the page.

Visible :hidden- makes the object invisible on the web page, but the space occupied by the object on the web page has not changed.

Example:
 
<html> 
<head> 
<title>display:none and visible:hidden The difference between </title> 
</head> 
<body > 
<span style="display:none; background-color:Blue"> Hidden area </span><span style=" background-color:Green"> Display area </span><br /> 
<span style="visibility:hidden; background-color:Blue"> Hidden area </span><span style="background-color:Green"> Display area </span> 
</body> 
</html> 

JQuery's show and hide methods
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title> Headless document </title> 
<script src="jquery_last.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready( function(){}); 
function hiden(){ 
$("#divObj").hide();//The hide() function, hidden, can also take a time parameter (milliseconds) in the parentheses, such as hide(2000) hidden at the speed of 2000 milliseconds, can also take slow,fast
} 
function slideToggle(){ 
$("#divObj").slideToggle(2000);//Of curtain effect toggle, point once accept, point once open, parameter can have no, parameter specification is same as above
} 
function show(){ 
$("#divObj").show();//Display, parameter description as above
} 
function toggle(){ 
$("#divObj").toggle(2000);//Show hide switch, parameter can be no, parameter description as above

} 
function slide(){ 
$("#divObj").slideDown();//Curtain effect unfolding
} 

</script> 
</head> 

<body> 
<h3>div Content in the show hidden effects </h3> 
<input type="button" value=" hidden " onclick="hiden()"/> 
<input type="button" value=" According to " onclick="show()"/> 
<input type="button" value=" Curtain effect display 2" onclick="slide()"/> 
<input type="button" value=" The switch of curtain effect " onclick="slideToggle()"/> 
<input type="button" value=" Hide display toggle " onclick="toggle()"/> 
<div id="divObj" style="display:none"> 
. Test cases <br/> 
. Test cases <br/> 
. Test cases <br/> 
. Test cases <br/> 
. Test cases <br/> 
. Test cases <br/> 
. Test cases <br/> 
. Test cases <br/> 
. Test cases <br/> 
. Test cases <br/> 
</div> 
</body> 
</html> 

Related articles: