Skip to content

Instantly share code, notes, and snippets.

View bridgetwes's full-sized avatar

Bridget Wessel bridgetwes

View GitHub Profile
@bridgetwes
bridgetwes / gist:b96b3135e750c586adf3e94ed9c0dcc9
Created December 27, 2023 21:21
Vanilla Javascript smooth scroll to element from URL hash - on load or from in page link
/*
*
* Smooth Scroll to Anchors
* */
const offsetTopScroll = 200;
//Smooth scroll on page load if anchor is in URL
if (window.location.hash) {
const hash = window.location.hash;
const target = document.getElementById(hash.replace('#', ''));
@bridgetwes
bridgetwes / gist:7ee61e7253161804dde057ae1caeda1f
Created December 27, 2023 21:25
jQuery smooth scroll to element from URL hash - on load or from in page link
//Smooth scroll on page load if anchor is in URL
if (window.location.hash) {
var hash = window.location.hash;
$('html,body').animate({
scrollTop: $(hash).offset().top - 200
}, 1000);
}
//Smooth scroll to anchor when clicking on a link
$('a[href*="#"]:not([href="#"])').click(function (event) {
@bridgetwes
bridgetwes / gist:3f1a6d1efdfb10768c04fc100c9c6ff8
Last active December 29, 2023 17:11
jQuery WP Go Maps - Use search, radius and/or categories in URL parameters to preselect map filters. Also add selected search, radius and categories to URL as user interacts with map so URL can be copied and sent to others
jQuery(function ($) {
$(document).ready(function () {
const baseUrl = window.location.href.split('?')[0];
//Set any search, radius and/or categories from URL params on map load
if (typeof WPGMZA != 'undefined' && WPGMZA != null) {
let url = new URL(window.location.href);
let search = url.searchParams.get("search");
let radius = url.searchParams.get("radius");
let categories = url.searchParams.get("categories");