jQuery fadeToggle()เมธอด

❮ วิธีการเอฟเฟกต์ jQuery

ตัวอย่าง

สลับระหว่างการเฟดเข้าและเฟดออกกล่องต่างๆ:

$("button").click(function(){
  $("#div1").fadeToggle();
});

ความหมายและการใช้งาน

วิธี fadeToggle() สลับไปมาระหว่างวิธีfadeIn ()และfadeOut()

หากองค์ประกอบจางหายไป fadeToggle() จะทำให้องค์ประกอบจางลง

หากองค์ประกอบจางลง fadeToggle() จะทำให้องค์ประกอบจางลง

หมายเหตุ : องค์ประกอบที่ซ่อนอยู่จะไม่ปรากฏเลย (ไม่ส่งผลต่อเค้าโครงของหน้าอีกต่อไป)


ไวยากรณ์

$(selector).fadeToggle(speed,easing,callback)

Parameter Description
speed Optional. Specifies the speed of the fading effect. Default value is 400 milliseconds

Possible values:

  • milliseconds
  • "slow"
  • "fast"
easing Optional. Specifies the speed of the element in different points of the effect. Default value is "swing"

Possible values:

  • "swing" - moves slower at the beginning/end, but faster in the middle
  • "linear" - moves in a constant speed
Tip: More easing functions are available in external plugins
callback Optional. A function to be executed after the fadeToggle() method is completed

To learn more about callback, please read our jQuery Callback chapter

ลองด้วยตัวคุณเอง - ตัวอย่าง


วิธีการใช้พารามิเตอร์ความเร็วเพื่อระบุความเร็วของเอฟเฟกต์การซีดจาง


วิธีการใช้พารามิเตอร์การเรียกกลับเพื่อดำเนินการฟังก์ชันหลังจากเมธอด fadeToggle() เสร็จสิ้น


❮ วิธีการเอฟเฟกต์ jQuery