当前位置: 首页 > 文档资料 > jQuery 入门教程 >

Scale

优质
小牛编辑
116浏览
2023-12-01

描述 (Description)

Scale效果可以与show/hide/toggle一起使用。 这会按百分比因子缩小或增加元素。

语法 (Syntax)

以下是使用此效果的简单语法 -

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

参数 (Parameters)

以下是所有论点的描述 -

  • direction - 效果的方向。 可以是“两者”,“垂直”或“水平”。 默认是两者。

  • from - 开始时的状态,通常不需要。 这将是一个对象,将以{height:..,width:..}的形式给出。

  • origin - 消失点。 这是一个数组,默认设置为['middle','center']。

  • percent - 要缩放的百分比,数字。 默认值为0/100。

  • scale - 元素的哪些区域将被调整大小:'both','box','content'框调整边框的大小和元素的填充内容调整元素内部的任何内容。 默认是两者。

例子 (Example)

以下是一个简单的例子,简单地展示了这种效果的用法 -

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://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>