Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Farmatique / gist:c5d568991a123e0a267410f30c1462a9
Last active May 4, 2020 14:54
Check if element is in viewport check if scrolled to element
//from here https://gomakethings.com/how-to-test-if-an-element-is-in-the-viewport-with-vanilla-javascript/
//NOTE: This script return true when ALL element is in the viewport, not only its part
var isInViewport = function (elem) {
var bounding = elem.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
@Farmatique
Farmatique / gist:278c54a63441da346d3777eb1531cb58
Created April 23, 2019 15:14
Animation for printed text js, type animation
function printed_el_text( el ){
var text = el.innerHTML,
i = 0,
__print = function (){
i++;
if( i <= text.length ){
el.innerHTML = text.substr(0, i);
setTimeout( __print, 20 );
}
};
@Farmatique
Farmatique / gist:853e4701e2c2b89e1f94a97cf8757f56
Created March 4, 2019 11:52
Prevent submit form on Enter press, except textarea
$(document).on("keypress", ":input:not(textarea)", function(event) {
return event.keyCode != 13;
});
@Farmatique
Farmatique / gist:de9cd418c51da9a7e334ec121ec2ca09
Created March 3, 2019 17:17
Wordpress custom excerpt custom text trim cut
<?php echo mb_strimwidth(get_sub_field('title'), 0, 50, '...'); ?>
@Farmatique
Farmatique / gist:3730d65e94ea881ebf3b6ca70c7c1ccf
Created February 12, 2019 19:13
Run code only on first visit site, run animation once
$(document).ready(function(){
if(!sessionStorage.getItem('isshow')){
// here run code for animation that will fire only on first visit
sessionStorage.setItem('isshow', true);
}
});
//https://stackoverflow.com/questions/32155036/show-jquery-popup-only-at-first-visit-of-a-page
@Farmatique
Farmatique / gist:fa30f3e70275f3fa2af938bca1b62d52
Created December 19, 2018 12:04
Wordpress: Get custom field ACF inside post
$project_3_works_bg_color = get_field('works-bg-color', $post->ID);
@Farmatique
Farmatique / gist:eabba0bd96bf8c81edac1dbcfb619dc4
Created December 3, 2018 21:29
Wordpress custom excerpt
// Custom excerpt
function excerpt($limit, $morelink) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt) >= $limit) {
array_pop($excerpt);
$excerpt = implode(" ", $excerpt) . $morelink;
} else {
$excerpt = implode(" ", $excerpt);
}
@Farmatique
Farmatique / gist:dbcf530970d57d7917cec0fe6711aed0
Created November 28, 2018 16:47
Wordpress URL in phpmyadmin SQL (when migrate, etc)
wp_options > siteurl
wp_options > home
For local: http://localhost/yoursitefolder or http://yourlocalip/yoursitefolder
Always clear cache in browser!
@Farmatique
Farmatique / gist:d5b2f89d899342e9939f07d699ba1a73
Created November 28, 2018 16:14
JS random number from set
function getRndmFromSet(set)
{
var rndm = Math.floor(Math.random() * set.length);
return set[rndm];
}
@Farmatique
Farmatique / gist:faa352371c289699f29c43c07a03f9dc
Last active November 21, 2018 15:32
Custom numbers dots styling in list ol ul
ol {
list-style: none;
counter-reset: item;
}
li {
counter-increment: item;
margin-bottom: 5px;
}
li:before {
margin-right: 10px;