Skip to content

Instantly share code, notes, and snippets.

@andreyshr
andreyshr / topButton
Last active September 16, 2017 10:04
topButton
<script>
$(function() {
$(window).scroll(function() {
if ($(this).scrollTop() != 0) {
$('#toTop').fadeIn();
} else {
$('#toTop').fadeOut();
}
});
$('#toTop').click(function() {
@andreyshr
andreyshr / clearfix
Created September 16, 2017 10:10
clearfix
.clearfix:after {
content: "";
display: table;
clear: both
}
@andreyshr
andreyshr / border-box
Created September 16, 2017 10:11
border-box
*,
*::before,
*::after {
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
@andreyshr
andreyshr / visually-hidden
Created September 16, 2017 10:12
visually-hidden
.visually-hidden {
position: absolute;
clip: rect(0 0 0 0);
width: 1px;
height: 1px;
margin: -1px;
}
@andreyshr
andreyshr / bottomButton
Last active September 25, 2017 11:58
bottomButton
$("#bottom").on("click", function (event) {
event.preventDefault();
var id = $(this).attr('href'),
top = $(id).offset().top;
$('body,html').animate({
scrollTop: top
}, 1200);
});
@andreyshr
andreyshr / randomNumber(min, max)
Last active August 2, 2018 07:38
randomNumber(min, max)
function randomNumber(min, max) {
return min + Math.floor(Math.random() * (max + 1 - min));
}
@andreyshr
andreyshr / sliceText(textNodes, symbols)
Last active August 2, 2018 07:38
sliceText(textNodes, symbols)
function sliceText(textNodes, symbols) {
textNodes.forEach(cur => {
const text = cur.innerText;
let sliced = text.slice(0,symbols);
if (sliced.length < text.length) {
sliced += '...';
cur.innerText = sliced;
}
});
@andreyshr
andreyshr / formatDigits(str)
Created August 2, 2018 07:43
formatDigits(str)
function formatDigits(str) {
return str.toString().replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
}
@andreyshr
andreyshr / horizontalWheelScroll()
Last active August 2, 2018 10:44
horizontalWheelScroll()
const container = document.querySelector('.scroll-container');
container.addEventListener('wheel', horizontalWheelScroll);
function horizontalWheelScroll (event) {
let modifier;
if (event.deltaMode === event.DOM_DELTA_PIXEL) {
modifier = 1;
// иные режимы возможны в Firefox
} else if (event.deltaMode === event.DOM_DELTA_LINE) {
modifier = parseInt(getComputedStyle(this).lineHeight);
@andreyshr
andreyshr / getSelectedText()
Last active September 21, 2018 09:48
getSelectedText()
// функция для получение выделенного текста
function getSelectedText(){
var text = "";
if (window.getSelection) {
text = window.getSelection();
}else if (document.getSelection) {
text = document.getSelection();
}else if (document.selection) {
text = document.selection.createRange().text;
}