Skip to content

Instantly share code, notes, and snippets.

@jeangontijo
jeangontijo / text_rendering.css
Last active June 14, 2018 14:38
Text Rendering
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
@jeangontijo
jeangontijo / aspect_ratio_calculator.html
Last active June 14, 2018 14:37
Aspect Ratio Calculator
<script type="text/javascript">
window.addEventListener("resize", aspectRatio);
function aspectRatio() {
var w = window.innerWidth;
var h = window.innerHeight;
var r = w/10;
var aspect = document.querySelector('pre');
var rounded = Math.round( h/r * 10 ) / 10;
aspect.innerHTML = "<pre style='position:fixed; top: 30px; right: 30px; color: #fff; background: #000; padding: 10px 20px; z-index: 99999999;'>"+ w/r +":"+ rounded +"</pre>";
}
@jeangontijo
jeangontijo / scroll_to_element.js
Last active June 14, 2018 14:42
Scroll to element
// <a href="#" onclick="doScrolling('#myID', 1500)">
function getElementY(query) {
return window.pageYOffset + document.querySelector(query).getBoundingClientRect().top
}
function doScrolling(element, duration) {
var startingY = window.pageYOffset
var elementY = getElementY(element)
var targetY = document.body.scrollHeight - elementY < window.innerHeight ? document.body.scrollHeight - window.innerHeight : elementY
@jeangontijo
jeangontijo / hover_on_touch.js
Last active June 14, 2018 14:40
Hover on Touch
// Replace :hover for .hover
var card = document.querySelectorAll('.card');
Array.prototype.slice.call(card).forEach(function(item) {
item.addEventListener('touchstart', function(e) {
this.classList.toggle("hover");
}, false);
item.addEventListener('mouseenter', function(e) {
this.classList.add("hover");
}, false);
@jeangontijo
jeangontijo / set_interval_change_class.js
Last active June 14, 2018 14:40
setInterval Change Class
var slider = document.getElementById("hero");
var classes = ['slide1', 'slide2', 'slide3', 'slide4'];
var myInterval = setInterval(function () {
changeClass()
}, 5000);
var i = 0;
function changeClass() {
@jeangontijo
jeangontijo / preloader.js
Last active June 14, 2018 14:39
Preloader
var interval = setInterval(function() {
if(document.readyState === 'complete') {
document.body.classList.remove('load');
clearInterval(interval);
}
}, 100);
@jeangontijo
jeangontijo / setviewport_onresize_function.js
Last active June 20, 2018 19:36
Set Viewport onResize Function
var ww;
var wh;
var setViewport = function () {
ww = window.innerWidth || document.documentElement.clientWidth;
wh = window.innerHeight || document.documentElement.clientHeight;
}
setViewport();
window.addEventListener('resize', function () {
setViewport();
@jeangontijo
jeangontijo / floating_label.scss
Last active June 14, 2018 14:41
Floating Label
.floating-label {
position: relative;
margin-bottom: 10px;
label {
position: absolute;
top: calc(50% - 7px);
left: 0;
opacity: 0;
transition: all .3s ease;
}
@jeangontijo
jeangontijo / toggle_data_attribute_onclick.js
Created June 6, 2018 21:08
Toggle Data Attribute on Click
var nav = document.querySelector('.nav__toggle');
var toggleState = function (elem, one, two) {
var elem = document.querySelector(elem);
elem.setAttribute('data-state', elem.getAttribute('data-state') === one ? two : one);
};
nav.onclick = function (e) {
toggleState('.nav ul', 'closed', 'open');
e.preventDefault();
};
@jeangontijo
jeangontijo / simple_autoplay_slider.js
Created June 14, 2018 14:24
Simple Autoplay Slider with Mask
// HTML
// <div class="container">
// <img src="https://picsum.photos/1920/1079" alt="">
// <img src="https://picsum.photos/1920/1081" alt="">
// <img src="https://picsum.photos/1921/1081" alt="">
// <img src="https://picsum.photos/1922/1081" alt="">
// </div>
// SCSS
// .container {