Skip to content

Instantly share code, notes, and snippets.

@wpmark
Created May 6, 2015 17:59
Show Gist options
  • Save wpmark/b2387235091a0cd1a399 to your computer and use it in GitHub Desktop.
Save wpmark/b2387235091a0cd1a399 to your computer and use it in GitHub Desktop.
Before and After Shortcode jQuery
/**
* 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