Skip to content

Instantly share code, notes, and snippets.

var lastScrollTop = 0;
$(window).scroll(function(){
var scrollTop = window.pageYOffset;
if(scrollTop > lastScrollTop){
console.log('down')
} else {
console.log('up')
}
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop;
})
@Farmatique
Farmatique / gist:5eda458715bc8730e074099221fb30b8
Created June 13, 2018 11:26
detect if element is in viewport
$(window).scroll(function() {
var top_of_element = $("#element").offset().top;
var bottom_of_element = $("#element").offset().top + $("#element").outerHeight();
var bottom_of_screen = $(window).scrollTop() + window.innerHeight;
var top_of_screen = $(window).scrollTop();
if((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){
// The element is visible, do something
}
else {
@Farmatique
Farmatique / gist:e45972e3c09ebcdff22f3a01736d105c
Last active May 21, 2018 20:14
Wordpress woocommerce catch change of variation select
$( ".variations_form" ).on( "woocommerce_variation_select_change", function () {
// Fires whenever variation selects are changed
} );
$( ".single_variation_wrap" ).on( "show_variation", function ( event, variation ) {
// Fired when the user selects all the required dropdowns / attributes
// and a final variation is selected / shown
} );
// another trick
@Farmatique
Farmatique / gist:414c7c963a7786ba6cd048323d0a2188
Created May 2, 2018 12:35
Change color of bullet inside LI
ul {
list-style: none;
line-height: 1em;
font-size: 3vw;
}
ul li:before {
content: "";
line-height: 1em;
width: .5em;
<div class="toggle">
<input type="checkbox" id="switcher" class="check">
<b class="switch"></b>
</div>
/* css */
.toggle {
display: inline-block;
vertical-align: middle;
margin: 10px;
@Farmatique
Farmatique / gist:61ecf28e7775ba15af917ddfebab1904
Last active March 9, 2018 16:03
Avoid flex items (flex child) to change (distort) width
apply to flex-childs
-webkit-flex-grow: 0;
flex-grow: 0;
-webkit-flex-shrink: 0;
flex-shrink: 0;
@Farmatique
Farmatique / gist:dd14c4675d259ea125bf8ad99e3a93ea
Created March 9, 2018 14:35
Bootstrap mobile nav menu side menu appear from right
source: https://jsfiddle.net/fk63zzbz/529/
<!-- Navigation -->
<div class="navbar navbar-default navbar-inverse" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
@Farmatique
Farmatique / gist:51ed163f060490ac713f7f9b32056e19
Last active March 8, 2018 13:12
Remove rounding from input and textarea in Safari
input, textarea {
-webkit-appearance: none;
border-radius: 0;
}
<span class="wpcf7-form-control wpcf7-radio">
<span class="wpcf7-list-item">
<label class="">
<input type="radio" value="Yes">
<span class="wpcf7-list-item-label">Yes</span>
</label>
</span>
</span>
@Farmatique
Farmatique / gist:4433d7b9e6e6084b5c294595728d7a11
Created February 8, 2018 15:34
Find if array of objects have an object with specific property name
myArray.filter(x => x.id === '45')
// it returns array with an object if its find matching object