Latest web development tutorials

jQuery UI contoh - efek khusus (Effect)

Penerapan unsur efek animasi.

Untuk informasi lebih lanjut tentang .effect() rincian metode, lihat dokumentasi API .effect () .

.effect () Demo

Klik tombol untuk melihat efek.

<! DOCTYPE html>
<Html lang = "en">
<Head>
  <Meta charset = "utf-8">
  <Title> jQuery UI Efek - .effect () Demo </ title>
  <Link rel = "stylesheet" href = "// code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <Script src = "// code.jquery.com/jquery-1.9.1.js"> </ script>
  <Script src = "// code.jquery.com/ui/1.10.4/jquery-ui.js"> </ script>
  <Link rel = "stylesheet" href = "http://jqueryui.com/resources/demos/style.css">
  <Gaya>
    .toggler {width: 500px; height: 200px; position: relative;}
    #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;}
    Ui-efek transfer {border: abu-abu putus-putus 2px;}
  </ Style>
  <Script>
  $ (Fungsi () {
    // Jalankan fungsi efek yang saat ini dipilih runEffect () {
      // Turunkan efek Jenis var selectedEffect = $ ( "#effectTypes") val ();
 
      // Sebagian besar efek tidak perlu mengetikkan pilihan opsi pengiriman default var = {};
      // Beberapa efek khusus dengan parameter yang diperlukan jika (selectedEffect === "skala") {
        Pilihan = {persen: 0};
      } Lain jika (selectedEffect === "Transfer") {
        Pilihan = {ke: "#button", className: "ui-efek transfer"};
      } Lain jika (selectedEffect === "ukuran") {
        Pilihan = {ke: {width: 200, height: 60}};
      }
 
      // Efek Jalankan $ ( "#effect") .effect (selectedEffect, opsi, 500, callback);
    };
 
    // Fungsi Callback callback () {
      setTimeout (function () {
        $ ( "#effect") .removeAttr ( "Style") .hide () fadeIn () .;
      }, 1000);
    };
 
    // Mengatur nilai sesuai dengan efek menu $ yang dipilih ( "#button") .Klik (function () {
      runEffect ();
      return false;
    });
  });
  </ Script>
</ Kepala>
<Body>
 
<Div class = "toggler">
  <Div id = "efek" class = "ui-widget-konten ui-sudut-semua">
    <Class H3 = "ui-widget-header ui-sudut-semua"> efek khusus (Effect) </ h3>
    <P>
      Etiam libero neque, luctus sebuah, eleifend nec, sempre di, lorem. Sed pede. Nulla lorem Metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
    </ P>
  </ Div>
</ Div>
 
<Pilih name = "efek" id = "effectTypes">
  <Value Option = "buta"> Shades efek (Blind Effect) </ option>
  <Value Option = "bouncing"> pulih efek (Bounce Efek) </ option>
  <Value Option = "klip"> efek Klip (Effect Clip) </ option>
  <Value Option = "drop"> efek Landing (Drop Effect) </ option>
  <Value Option = "meledak"> efek ledakan (Explode Effect) </ option>
  <Value Option = "fade"> Fade efek (Fade Effect) </ option>
  <Value Option = "lipat"> efek lipat (Lipat Effect) </ option>
  <Value Option = "highlight"> efek highlight (Sorot Effect) </ option>
  <Option value = "meniup"> efek ekspansi (Puff Effect) </ option>
  <Value Option = "berdenyut"> mengalahkan efek (berdenyut Effect) </ option>
  <Option value = "skala"> efek Zoom (Skala Effect) </ option>
  <Value Option = "goyang"> efek Getaran (Goyang Effect) </ option>
  <Option value = "size"> efek Size (Ukuran Effect) </ option>
  <Option value = "slide"> efek geser (Slide Effect) </ option>
  <Option value = "Transfer"> efek Transfer (Efek Transfer) </ option>
</ Pilih>
 
<a href="#" id="button" class="ui-state-default ui-corner-all"> menjalankan efek </a>
 
 
</ Body>
</ Html>

Mempermudah Demo

Contoh ini menggunakan HTML Canvas elemen, menarik semua easing jQuery UI menyediakan. Klik pada setiap peta untuk melihat perilaku pelonggaran. .

<! DOCTYPE html>
<Html lang = "en">
<Head>
  <Meta charset = "utf-8">
  <Title> jQuery UI Effects - Mempermudah Demo </ title>
  <Link rel = "stylesheet" href = "// code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <Script src = "// code.jquery.com/jquery-1.9.1.js"> </ script>
  <Script src = "// code.jquery.com/ui/1.10.4/jquery-ui.js"> </ script>
  <Link rel = "stylesheet" href = "http://jqueryui.com/resources/demos/style.css">
  <Gaya>
  .graph {
    float: kiri;
    margin-left: 10px;
  }
  </ Style>
  <Script>
  $ (Fungsi () {
    if (! $ ( "<canvas>") [0] .getContext) {
      $ ( "<Div>") .text (
        "Browser Anda tidak mendukung kanvas, ini menunjukkan kebutuhan untuk mendukung kanvas di browser."
      ) .appendTo ( "#graphs");
      kembali;
    }
 
    var i = 0,
      width = 100,
      height = 100;
 
    $ .each ($ .easing, Fungsi (nama, impl) {
      var grafik = $ ( "<div>") .addClass ( "Grafik") .appendTo ( "#graphs"),
        text = $ ( "<div>") .text (++ i + "." + nama) .appendTo (grafik),
        membungkus = $ ( "<div>") .appendTo (grafik) css ( 'melimpah', 'tersembunyi'),
        kanvas = $ ( "<canvas>") .appendTo (wrap) [0];
 
      canvas.width = lebar;
      canvas.height = tinggi;
      var drawHeight = tinggi * 0,8,
        cradius = 10;
        ctx = canvas.getContext ( "2d");
      ctx.fillStyle = "hitam";
 
      // Menggambar latar belakang ctx.beginPath ();
      ctx.moveTo (cradius, 0);
      ctx.quadraticCurveTo (0, 0, 0, cradius);
      ctx.lineTo (0, tinggi - cradius);
      ctx.quadraticCurveTo (0, tinggi, cradius, tinggi);
      ctx.lineTo (lebar - cradius, tinggi);
      ctx.quadraticCurveTo (lebar, tinggi, lebar, tinggi - cradius);
      ctx.lineTo (lebar, 0);
      ctx.lineTo (cradius, 0);
      ctx.fill ();
 
      // Menggambar garis bawah ctx.strokeStyle = "# 555";
      ctx.beginPath ();
      ctx.moveTo (lebar * 0,1, drawHeight + 0,5);
      ctx.lineTo (lebar * 0,9, drawHeight + 0,5);
      ctx.stroke ();
 
      // Menggambar garis atas ctx.strokeStyle = "# 555";
      ctx.beginPath ();
      ctx.moveTo (lebar * 0,1, drawHeight * 0,3-0,5);
      ctx.lineTo (lebar * 0,9, drawHeight * 0,3-0,5);
      ctx.stroke ();
 
      // Menggambar pelonggaran
      ctx.strokeStyle = "putih";
      ctx.beginPath ();
      ctx.lineWidth = 2;
      ctx.moveTo (lebar * 0,1, drawHeight);
      $ .each (Array New (lebar), fungsi (posisi) {
        negara var = posisi / lebar,
          val = impl (negara, posisi, 0, 1, lebar);
        ctx.lineTo (posisi * 0,8 + lebar * 0,1,
          drawHeight - drawHeight * val * 0,7);
      });
      ctx.stroke ();
 
      // Dinamis mengubah klik graph.click (function () {
        membungkus
          .animate ({height: "menyembunyikan"}, 2000, nama)
          .delay (800)
          .animate ({height: "show"}, 2000, nama);
      });
 
      graph.width (lebar) .height (tinggi + text.height () + 10);
    });
  });
  </ Script>
</ Kepala>
<Body>
 
<Div id = "grafik"> </ div>
 
 
</ Body>
</ Html>