Created
May 6, 2015 17:59
-
-
Save wpmark/b2387235091a0cd1a399 to your computer and use it in GitHub Desktop.
Before and After Shortcode jQuery
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
/** | |
* trigger the before and after images | |
*/ | |
var beforeafter = function() { | |
/* get the preceeding element before the toggle button - hides all the after images */ | |
$( '.before-after-toggle' ).prev().hide(); | |
/* when the element with 'before-after-toggle' class is clicked */ | |
$( '.before-after-toggle' ).click(function() { | |
/* hide the before image and show the after image */ | |
$( this ).siblings( '.after-image' ).toggle(); | |
$( this ).siblings( '.before-image' ).toggle(); | |
/* toggle a class on the button itself */ | |
$( '.before-after-toggle' ).toggleClass( 'active' ); | |
}); | |
}; | |
$(document).ready(beforeafter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment