Skip to content

Instantly share code, notes, and snippets.

@oliverll1
oliverll1 / gist:0943a8abccf52b9407e56960acfdf403
Created July 22, 2019 18:11
Change header background on scroll
function runOnScroll() {
const header = document.getElementById("header");
const bodyScroll = document.getElementsByTagName("body")[0].scrollTop;
// Chrome
const htmlScroll = document.getElementsByTagName("html")[0].scrollTop;
if ( bodyScroll >= 400 || htmlScroll >= 400) {
header.style.background = "#615e5d";
}
else{
@oliverll1
oliverll1 / gist:14200bfbcf295b5f2db0ce10bda962c1
Last active July 22, 2019 18:16
Handle Media queries in Javascript
const isMobile = window.matchMedia("only screen and (max-width: 768px)").matches;
if (isMobile) {
console.log("You are on mobile!");
}
add_action('template_redirect','my_non_logged_redirect');
function my_non_logged_redirect()
{
if(is_page('login') || is_page('my-account')){
return;
}
if ( !is_user_logged_in() ){
ob_clean();
@oliverll1
oliverll1 / vanillaAjax.js
Last active April 16, 2020 23:54
send form with ajax (vanilla JS)
const sendForm = async function(form){
let XHR = new XMLHttpRequest();
let FD = new FormData(form);
window.location.reload();
@oliverll1
oliverll1 / ajax-post-request-response.php
Last active November 5, 2019 12:26
Sending response from ajax post request on php
<?php
$post_request = json_decode(file_get_contents('php://input'));
$requestArray = get_object_vars($post_request);
$data = $requestArray['data'];
?>
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const param = urlParams.get('param');
console.log(param );