Skip to content

Instantly share code, notes, and snippets.

View adamfaux85's full-sized avatar

Adam adamfaux85

  • Manchester, England
View GitHub Profile
@adamfaux85
adamfaux85 / common_javascript_commands.js
Last active September 27, 2019 11:23
Common JS commands
// Get Data Attribute
// ------------------------------------------------------------------------------------------
var elemData = elem.getAttribute('data-label');
// Remove from DOM
// ------------------------------------------------------------------------------------------
elemToDelete.parentNode.removeChild(elemToDelete);
@adamfaux85
adamfaux85 / js_scrolling_direction_detection.js
Created May 17, 2019 09:26
Vanilla JS: Scrolling up or down
let scrollPos = 0;
const Elem = document.querySelector('.element');
function checkPosition() {
let windowY = window.scrollY;
if (windowY < scrollPos) {
// Scrolling UP
Elem.classList.add('is-visible');
Elem.classList.remove('is-hidden');
} else {
@adamfaux85
adamfaux85 / js_fixed_header_on_scroll.js
Created May 17, 2019 09:19
Vanilla JS: Fixed header on scroll
let scrollpos = window.scrollY
const headerElem = document.querySelector(".dress-details")
const headerElemHeight = headerElem.offsetHeight
const add_class_on_scroll = () => headerElem.classList.add("fixed")
const remove_class_on_scroll = () => headerElem.classList.remove("fixed")
window.addEventListener('scroll', function() {
scrollpos = window.scrollY;
if (scrollpos >= headerElemHeight) { add_class_on_scroll() }
else { remove_class_on_scroll() }
@adamfaux85
adamfaux85 / php_output_svg_file_contents.php
Created March 27, 2019 15:16
PHP / SVG: Output SVG code in PHP
<?php echo file_get_contents(getcwd() . '/wp-content/themes/basetheme/assets/svg/images-optimized/svg-image.svg'); ?>
@adamfaux85
adamfaux85 / php_pregreplace_link.php
Created March 27, 2019 11:59
PHP: Preg replace to add a data attribute to a link
@adamfaux85
adamfaux85 / other_browser_media_queries.scss
Created October 23, 2018 12:49
Browser Media Queries
// Webkit (Chrome & Safari, any version)
@media screen and (-webkit-min-device-pixel-ratio:0) {
// style.
}
// Firefox (any version)
@-moz-document url-prefix() {
// style.
}
@adamfaux85
adamfaux85 / ie_media_queries.scss
Created October 23, 2018 12:46
IE Media Queries
// IE8, IE9, IE10
@media screen\0 {
// styles
}
// IE9 Only
@media screen and (min-width:0\0) and (min-resolution: .001dpcm) {
// styles
}
@adamfaux85
adamfaux85 / css_aspect_ratios.sass
Last active August 14, 2018 11:04
CSS Set aspect ratio for an element
// This approach is based upon the elements width.
.element {
position: relative;
width: 100%;
display: block;
&:after {
display: block;
content: '';
@adamfaux85
adamfaux85 / Toggle_Classes_in_JS_After_Animation.js
Last active February 21, 2018 12:51
Add / Remove animation classes in jQuery
## TOGGLE CLASSES IN JAVASCRIPT AFTER ANIMATION END
// Example taken from Animation.css
// - https://daneden.github.io/animate.css/
function testAnim(x) {
$('#animationSandbox').removeClass().addClass(x + ' animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
$(this).removeClass();
});
};