Skip to content

Instantly share code, notes, and snippets.

@lukecav
lukecav / functions.php
Created June 14, 2019 18:58
Native Lazy Load to oEmbed iFrames in WordPress
function lazy_embed_oembed_html($html, $url, $attr){
$html = str_replace('<iframe ','<iframe loading="lazy" ',$html);
return $html;
}
add_filter('embed_oembed_html', 'lazy_embed_oembed_html',10, 3);
@ohiosveryown
ohiosveryown / change-class-on-scroll.html
Last active October 13, 2025 00:13
Vanilla JS – change/add class based on scroll position.
// https://codepen.io/cmykw/pen/gemxJm
// layout
<nav/>
// style
<style>
body { min-height: 200vh; }
nav {
@timersys
timersys / gist:d68690a85aed14a02318
Last active September 25, 2024 20:09
Wordpress popups - Open popup with link
// To open popup with ID 3 on same page (preferred)
<a href="" class="spu-open-3" title="Click here">Click here</a>
// Another way
<a href="#spu-3" title="Click here">Click here</a>
// To go to a new page and open a popup there
<a href="http://mydomain.com/new-page/#spu-3" title="Click here">Click here</a>
@robertcedwards
robertcedwards / gist:fcec06dc0904a438c6a8
Created November 3, 2014 21:35
onmouseover html5 video play, mouseout pause
<html>
<head>
</head>
<body>
<div style="text-align:center" onmouseover="Play()" onmouseout="Pause()">
<video id="video1" width="480">
<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4" />
<source src="http://clips.vorwaerts-gmbh.de/VfE_html5.ogg" type="video/ogg" />
Your browser does not support HTML5 video.
</video>
@cferdinandi
cferdinandi / stop-video.js
Last active August 2, 2025 14:10
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
/**
* Stop an iframe or HTML5 <video> from playing
* @param {Element} element The element that contains the video
*/
var stopVideo = function ( element ) {
var iframe = element.querySelector( 'iframe');
var video = element.querySelector( 'video' );
if ( iframe ) {
var iframeSrc = iframe.src;
iframe.src = iframeSrc;
@davidtheclark
davidtheclark / isElementInViewport.js
Created May 4, 2013 02:00
JavaScript: Is element in viewport?
/*
No jQuery necessary.
Thanks to Dan's StackOverflow answer for this:
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
*/
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&