Szukaj…


Parametry

Parametr Detale
Trwanie Po przejściu efekty .hide() , .show() i .toggle() są animowane; element (y) będą stopniowo zanikały lub zanikały.

Przegląd

$(element).hide()            // sets display: none
$(element).show()            // sets display to original value
$(element).toggle()          // toggles between the two
$(element).is(':visible')    // returns true or false
$('element:visible')         // matches all elements that are visible
$('element:hidden')          // matches all elements that are hidden

$('element').fadeIn();          // display the element
$('element').fadeOut();          // hide the element

$('element').fadeIn(1000);          // display the element using timer
$('element').fadeOut(1000);          // hide the element using timer

// display the element using timer and a callback function
$('element').fadeIn(1000, function(){
 // code to execute
});          

// hide the element using timer and a callback function
$('element').fadeOut(1000, function(){
   // code to execute
});       

Przełącz możliwości

Prosta toggle() liter toggle()

function toggleBasic() {
  $(".target1").toggle();
}

Z określonym czasem trwania

function toggleDuration() {
  $(".target2").toggle("slow"); // A millisecond duration value is also acceptable
}

... i oddzwonienie

function toggleCallback() {
  $(".target3").toggle("slow",function(){alert('now do something');});  
}

... lub z łagodzeniem i oddzwanianiem.

function toggleEasingAndCallback() {
  // You may use jQueryUI as the core only supports linear and swing easings
  $(".target4").toggle("slow","linear",function(){alert('now do something');});  
}

... lub z różnymi opcjami .

function toggleWithOptions() {
  $(".target5").toggle(
    { // See all possible options in: api.jquery.com/toggle/#toggle-options
      duration:1000, // milliseconds
      easing:"linear",
      done:function(){
        alert('now do something');
      }
    }
  );  
}

Możliwe jest również użycie slajdu jako animacji za pomocą slideToggle()

function toggleSlide() {
  $(".target6").slideToggle(); // Animates from top to bottom, instead of top corner
}

... lub fadeToggle() / zmniejszania poprzez zmianę krycia za pomocą fadeToggle()

function toggleFading() {
  $( ".target7" ).fadeToggle("slow")
}

... lub przełącz klasę za pomocą toggleClass()

function toggleClass() {
  $(".target8").toggleClass('active');
}

Częstym przypadkiem jest użycie toggle() w celu pokazania jednego elementu podczas ukrywania drugiego (tej samej klasy)

function toggleX() {
  $(".targetX").toggle("slow");  
}

Wszystkie powyższe przykłady można znaleźć tutaj



Modified text is an extract of the original Stack Overflow Documentation
Licencjonowany na podstawie CC BY-SA 3.0
Nie związany z Stack Overflow