jQuery Effect - Scale Effect


Advertisements


Description:

The Scale effect can be used with show/hide/toggle. This shrinks or grows an element by a percentage factor.

Syntax:

Here is the simple syntax to use this effect:

selector.hide|show|toggle( "scale", {arguments}, speed );

Parameters:

Here is the description of all the arguments:

  • direction: The direction of the effect. Can be "both", "vertical" or "horizontal". Default is both.

  • from: The state at beginning, usually not needed. This would be an object and would be given in the form of { height: .., width: .. }.

  • origin: The vanishing point. This is an array and by default set to ['middle','center'].

  • percent: The percentage to scale to, number. Default is 0/100.

  • scale: Which areas of the element will be resized: 'both', 'box', 'content' Box resizes the border and padding of the element Content resizes any content inside of the element. Default is both.

Example:

Following is a simple example a simple showing the usage of this effect:

<html>
<head>
<title>The jQuery Example</title>
   <script type="text/javascript" 
   src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
   <script type="text/javascript" 
   src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
   <script type="text/javascript" language="javascript">
   
    $(document).ready(function() {

      $("#hide").click(function(){
         $(".target").hide( "scale", 
          {percent: 200, direction: 'horizontal'}, 2000 );
      });

      $("#show").click(function(){
         $(".target").show( "scale", 
         {percent: 200, direction: 'vertical' }, 2000 );
      });

   });
   </script>
   <style>
      p {
           background-color:#bca;
           width:200px; 
           border:1px solid green; 
        }
     div{ width:100px; 
            height:100px; 
            background:red;  
        }
  </style>
</head>
<body>

   <p>Click on any of the buttons</p>
   <button id="hide"> Hide </button>
   <button id="show"> Show</button> 
  
   <div class="target">
   </div>
  
</body>
</html>