Skip to content

Instantly share code, notes, and snippets.

@timn5835
timn5835 / main.js
Created January 11, 2021 16:36
[Local Storage] Stores a value in browser local storage #js #localstorage #cookies
var alerted = getWithExpiry('covid19');
if (alerted != 'yes') {
$('.alert-dismissible.orange-bg.pr-0').addClass('d-flex');
}
$('body').on('close.bs.alert', '.alert-dismissible.orange-bg.pr-0', function () {
// localStorage.setItem('covid19','yes');
setWithExpiry('covid19', 'yes', 3600000)
});
@timn5835
timn5835 / main.js
Last active January 11, 2021 16:32
[Vimeo API] Play/pause vimeo embeds on modal open/close #js #bootstrap #vimeo #modals
/*
Add this to functions.php
function enqueue_scripts() {
wp_enqueue_script( 'vimeo-api', '//player.vimeo.com/api/player.js', true);
}
*/
// Vimeo API Documentation: https://developer.vimeo.com/api/reference
// Pause video on modal close
@timn5835
timn5835 / main.js
Created January 11, 2021 16:27
[Scroll Animations] How to use animate.css library to fadin/out/slide/etc on scroll #js #scroll #animate
// Library url: https://animate.style/
// SCROLL ANIMATION
// Check if element is scrolled into view
function isScrolledIntoView(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
@timn5835
timn5835 / main.js
Created January 11, 2021 16:21
[Scroll to Top] #js #scroll
// ANIMATE TO THE TOP
$('button#to-top').on('click', function(e) {
animateScroll(0, 650);
// GA Custom Click Tracking
gtag('event','Click',{'event_category':'clicktrack','event_label':'Up Arrow'});
})
@timn5835
timn5835 / main.js
Created January 11, 2021 16:15
[Animate Scroll] #js #scroll
// ANIMATE ANCHOR SCROLL
const $root = $('html, body');
function animateScroll(yPos, speed) {
$root.animate({
scrollTop: yPos
}, speed);
}
// Stops the page load and animates scroll
$('ul#main-menu').on('click', 'a[href^="#"]', function(e) {