目录

JqueryUI - Show

本章将讨论show()方法,它是用于管理jQueryUI视觉效果的方法之一。 show()方法使用指示的效果显示项目。

show()方法使用指定的效果切换包装元素的可见性。

语法 (Syntax)

show()方法具有以下语法 -

.show( effect [, options ] [, duration ] [, complete ] )
Sr.No. 参数和描述
1

effect

这是一个String,指示要用于转换的效果。这是一个String,表示调整元素可见性时要使用的效果。 效果列于下表中。

2

options

这是Object类型,表示特定于效果的设置easing 。 此外,每个效果都有自己的一组选项,可以在表jQueryUI Effects描述的多个效果中共同指定。

3

duration

它的类型为Number或String,用于确定动画的运行时间。 其默认值为400

4

complete

这是对此元素的效果完成时为每个元素调用的回调方法。

jQueryUI效果

下表描述了可以与effects()方法一起使用的各种效果 -

Sr.No. 效果和描述
1

blind

以窗帘的方式显示或隐藏元素:向下或向上移动底边,或向右或向左移动右边边,具体取决于指定的directionmode

2

bounce

使元素看起来在垂直或水平方向上反弹,可选地显示或隐藏元素。

3

clip

通过将元素的相对边界移动到一起直到它们在中间相遇来显示或隐藏元素,反之亦然。

4

drop

通过使元素显示为放下或删除页面来显示或隐藏元素。

5

explode

通过将元素拆分为多个在径向方向上移动的片段来显示或隐藏元素,就像在页面中嵌入或爆炸一样。

6

fade

通过调整其不透明度来显示或隐藏元素。 这与核心淡入淡出效果相同,但没有选项。

7

fold

通过调整或调出相反的边框来显示或隐藏元素,然后对另一组边框执行相同的操作。

8

highlight

通过在显示或隐藏元素时暂时更改其背景颜色来调用元素。

9

puff

在调整其不透明度的同时扩展或收缩元素。

10

pulsate

在确保按指定显示或隐藏元素之前,调整元素的不透明度。

11

scale

按指定百分比扩展或收缩元素。

12

shake

垂直或水平地来回摇动元件。

13

size

将元素的大小调整为指定的宽度和高度。 与规模类似,但指定目标大小的方式除外。

14

slide

移动元素,使其看起来可以滑入或滑出页面。

15

transfer

动画一个瞬态轮廓元素,使元素看起来转移到另一个元素。 必须通过ui-effects-transfer类的CSS规则或指定为选项的类来定义outline元素的外观。

例子 (Examples)

以下示例演示了show()方法的用法。

显示摇动效果

以下示例演示了具有shake效果的show()方法。

<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <title>jQuery UI show Example</title>
      <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">
      <script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
      <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
      <!-- CSS -->
      <style>
         .toggler { width: 500px; height: 200px; }
         #button { padding: .5em 1em; text-decoration: none; }
         #effect { width: 240px; height: 135px; padding: 0.4em; position: relative; }
         #effect h3 { margin: 0; padding: 0.4em; text-align: center; }
      </style>
      <script>
         $(function() {
            // run the currently selected effect
            function runEffect() {
               // run the effect
               $( "#effect" ).show( "shake", {times: 10,distance: 100}, 1000, callback);
            };
            //callback function to bring a hidden box back
            function callback() {
               setTimeout(function() {
                  $( "#effect:visible" ).removeAttr( "style" ).fadeOut();
               }, 1000 );
            };
            $( "#button" ).click(function() {
               runEffect();
               return false;
            });
            $( "#effect" ).hide();
         });
      </script>
   </head>
   <body>
      <div class = "toggler">
         <div id = "effect" class = "ui-widget-content ui-corner-all">
            <h3 class = "ui-widget-header ui-corner-all">Show</h3>
            <p>
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.
            </p>
         </div>
      </div>
      <a href = "#" id = "button" class = "ui-state-default ui-corner-all">Run Effect</a>
   </body>
</html>

让我们将上面的代码保存在HTML文件showexample.htm ,并在支持javascript的标准浏览器中打开它,您还必须看到以下输出。 现在,你可以玩结果 -

新页面打开

单击“ Add Class和“ Remove Class按钮以查看类对该框的影响。

显示盲目效果

以下示例演示了使用show()方法的blind效果。

<!doctype html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <title>jQuery UI show Example</title>
      <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">
      <script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
      <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
      <!-- CSS -->
      <style>
         .toggler { width: 500px; height: 200px; }
            #button { padding: .5em 1em; text-decoration: none; }
            #effect { width: 240px; height: 135px; padding: 0.4em; position: relative; }
            #effect h3 { margin: 0; padding: 0.4em; text-align: center; }
      </style>
      <script>
         $(function() {
            // run the currently selected effect
            function runEffect() {
               // run the effect
               $( "#effect" ).show( "blind", {times: 10,distance: 100}, 1000, callback);
            };
            //callback function to bring a hidden box back
            function callback() {
               setTimeout(function() {
                  $( "#effect:visible" ).removeAttr( "style" ).fadeOut();
               }, 1000 );
            };
            // set effect from select menu value
            $( "#button" ).click(function() {
               runEffect();
               return false;
            });
            $( "#effect" ).hide();
         });
      </script>
   </head>
   <body>
      <div class = "toggler">
         <div id = "effect" class = "ui-widget-content ui-corner-all">
            <h3 class = "ui-widget-header ui-corner-all">Show</h3>
            <p>
               Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore.
            </p>
         </div>
      </div>
      <a href = "#" id = "button" class = "ui-state-default ui-corner-all">Run Effect</a>
   </body>
</html>

让我们将上面的代码保存在HTML文件showexample.htm ,并在支持javascript的标准浏览器中打开它,您还必须看到以下输出。 现在,你可以玩结果 -

新页面打开
↑回到顶部↑
WIKI教程 @2018