Skip to content

Instantly share code, notes, and snippets.

View BroFox86's full-sized avatar

Daur Gamisonia BroFox86

View GitHub Profile
@BroFox86
BroFox86 / mixin.scss
Last active March 31, 2021 10:50
[Triangle mixin] #mixin
@mixin triangle($direction, $color, $sizeW, $sizeH: $sizeW) {
content: "";
display: inline-block;
width: 0;
height: 0;
border-style: solid;
@if $direction == top {
border-width: 0 ($sizeW / 2) $sizeH ($sizeW / 2);
border-color: transparent transparent $color transparent;
@BroFox86
BroFox86 / script.js
Last active December 16, 2020 20:25
[Pause audio] Pause previous track when the next track starts playing #media
// Pause current track when another track starts playing.
document.addEventListener("play", ({ target }) => {
const audios = document.querySelectorAll("audio");
for ( const audio of audios ) {
if ( audio !== target ) {
audio.pause();
}
}
@BroFox86
BroFox86 / macro.html
Last active December 19, 2022 16:14
[Responsive image] Pug/Nunjucks responsive image mixin/macro #responsive
{% macro respImg(
class,
srcset,
sizes,
src,
width = "",
height = "",
loading = "",
alt = ""
)%}
@BroFox86
BroFox86 / snippet.js
Last active May 28, 2024 18:30
[isInViewportArea] Check if element has reached specific viewport area #jsTrick
function isInViewportArea( element ) {
const coords = getCoords( element );
const viewportTop = pageYOffset;
const viewportBottom = pageYOffset + document.documentElement.clientHeight;
// If an element has appeared on the bottom.
if ( viewportBottom > coords.top ) {
return true;
}
@BroFox86
BroFox86 / snippet.js
Last active May 28, 2024 18:34
[Mutation observer] Constructor for instantiating new DOM mutation observers #jsTrick
/* ==========================================================================
Constructor for instantiating new DOM mutation observers.
More info here: https://developer.mozilla.org/ru/docs/Web/API/MutationObserver
Objects list: https://developer.mozilla.org/en-US/docs/Web/API/MutationRecord
========================================================================== */
// Select the node that will be observed for mutations
var target = document.getElementById('some-id');
// Create the MutationObserver
@BroFox86
BroFox86 / snippet.scss
Last active April 6, 2022 11:12
[Responsive background] #responsive CSS background image via media queries
//
// Responsive background image via media queries. More info here:
// developers.google.com/web/fundamentals/design-and-ux/responsive/images
//
.block {
// Mobile standard image.
background-image: url("../images/mobile.png");
background-repeat: no-repeat;
background-size: contain;
@BroFox86
BroFox86 / markup.html
Last active May 28, 2024 18:34
[Google map] #gmap
<div class="container">
<div data-toggle="map"></div>
</div>
@BroFox86
BroFox86 / snippet.scss
Last active March 11, 2021 21:22
[Semicircle] Simple semicircle with border #csstrick
.semicircle {
width: 200px;
height: 100px;
border: 10px solid gray;
background-color: gold;
border-top-left-radius: 100px;
border-top-right-radius: 100px;
border-bottom: 0;
box-sizing: border-box;
}
@BroFox86
BroFox86 / snippet.js
Last active May 28, 2024 18:35
[documentHeight] Get page height #gettingValue
const documentHeight = Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);
@BroFox86
BroFox86 / snippet.js
Last active May 28, 2024 18:30
[isNumber] Check if value is number #jsTrick
function isNumber( x ) {
return !isNaN( parseFloat( x ) ) && isFinite( x );
}