Last active
February 4, 2022 01:40
-
-
Save wplit/f52ca9849976adbae1bad3a55749d3cb to your computer and use it in GitHub Desktop.
close lightbox when element clicked, open lightbox on page load if hash matches
This file contains 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
jQuery(document).ready(function($) { | |
let openSelector = '.open-lightbox'; | |
let closeSelector = '.close-lightbox'; | |
let hash = 'form' /* yourwebsite.com/#form */ | |
/* | |
* close open lightbox when element clicked | |
*/ | |
$(closeSelector).on('click', function(e) { | |
e.preventDefault(); | |
$.fancybox.close(); | |
}); | |
/* | |
* open lightbox on page load by triggering a click on the click trigger if hash matches | |
*/ | |
if(window.location.hash) { | |
let hashinURL = window.location.hash.substring(1); | |
if (hashinURL === hash) { | |
$(openSelector).trigger('click'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment