jQuery slideToggle()เมธอด

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

ตัวอย่าง

สลับระหว่าง slideUp() และ slideDown() สำหรับองค์ประกอบ <p> ทั้งหมด:

$("button").click(function(){
  $("p").slideToggle();
});

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

เมธอด slideToggle() จะสลับไปมาระหว่างslideUp() และslideDown()สำหรับองค์ประกอบที่เลือก

วิธีนี้จะตรวจสอบองค์ประกอบที่เลือกเพื่อให้มองเห็นได้ slideDown() จะทำงานหากองค์ประกอบถูกซ่อน slideUp() จะทำงานหากองค์ประกอบมองเห็นได้ - สิ่งนี้จะสร้างเอฟเฟกต์สลับ


ไวยากรณ์

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

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

Possible values:

  • milliseconds
  • "slow"
  • "fast"
easing Optional. Specifies the speed of the element in different points of the animation. 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 slideToggle() method is completed

To learn more about callback, visit our jQuery Callback chapter


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


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


วิธีการใช้พารามิเตอร์การโทรกลับเมื่อสลับไปมาระหว่าง slideUp() และ slideDown()


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