Created
April 3, 2017 05:44
-
-
Save rg3915/321c3ae4d7225a896aeadacef230ac39 to your computer and use it in GitHub Desktop.
fadeToggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button class="btn btn-success mybtn">Ocultar</button> | |
<p>Com o comando <code>fadeToggle()</code> podemos ocultar ou mostrar um elemento.</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Alterna o texto de um elemento. | |
$.fn.extend({ | |
toggleText: function(a, b) { | |
return this.text(this.text() == b ? a : b); | |
} | |
}); | |
$(".mybtn").on('click', function(e) { | |
e.preventDefault(); | |
// Pega o próximo elemento, no caso o primeiro parágrafo. | |
$(this).next().fadeToggle('slow', 'linear'); | |
$(this).toggleText('Ocultar', 'Mostrar'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment