Skip to content

Instantly share code, notes, and snippets.

View SashaKolbasov's full-sized avatar

Alex SashaKolbasov

View GitHub Profile
@SashaKolbasov
SashaKolbasov / events.js
Last active April 11, 2016 18:24
Cross-browser events on JavaScript.
var eventsObj = {
addEvent: function (el, type, fn) {
if (typeof addEventListener !== 'undefined') {
el.addEventListener(type, fn, false);
} else if (typeof attachEvent !== 'undefined') {
el.attachEvent('on' + type, fn);
} else {
el['on' + type] = fn;
}
},
@SashaKolbasov
SashaKolbasov / script.js
Last active January 4, 2017 08:59
Scrollbar Width
function scrollWidth() {
var div = document.createElement('div');
div.style.overflowY = 'scroll';
div.style.width = '50px';
div.style.height = '50px';
div.style.visibility = 'hidden';
document.body.appendChild(div);
var s = div.offsetWidth - div.clientWidth;
document.body.removeChild(div);
return s;
@SashaKolbasov
SashaKolbasov / smoothscroll.js
Last active January 4, 2017 09:00
Smooth page scrolling.
// scrollTo
var scrolllink = $('selector');
scrolllink.click(function () {
var idscroll = $(this).attr('href');
$.scrollTo(idscroll, 1000, {
margin: 'true',
offset: -80
});
return false;
});
@SashaKolbasov
SashaKolbasov / style.less
Created January 4, 2017 09:44
Footer Clamp Down
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
.wrapper {
display: flex;
@SashaKolbasov
SashaKolbasov / style.less
Created January 4, 2017 09:46
Placeholder Focus
.plchfcs {
opacity: 1;
transition: opacity .15s ease-out;
}
input {
&::-webkit-input-placeholder {
.plchfcs;
}
&::-moz-placeholder {
.plchfcs;
@SashaKolbasov
SashaKolbasov / script.js
Last active January 4, 2017 09:47
Form Reset
$('form').submit(function() {
$(this).trigger("reset");
});
@SashaKolbasov
SashaKolbasov / script.js
Created January 4, 2017 19:01
Body Click to Hide block
$('body').click(function (e) {
if ($(e.target).closest('selector').length == 0) {
$('selector').removeClass('_active');
}
});
@SashaKolbasov
SashaKolbasov / script.js
Last active January 8, 2017 12:38
Change SVG Color
$('img[src$=".svg"]').each(function () {
var $img = $(this),
imgID = $img.attr('id'),
imgClass = $img.attr('class'),
imgURL = $img.attr('src');
$.get(imgURL, function (data) {
var $svg = $(data).find('svg');
if (typeof imgID !== 'undefined') {
$svg = $svg.attr('id', imgID);
}
@SashaKolbasov
SashaKolbasov / html.html
Last active January 13, 2017 19:09
Easy Preloader
<div id="preloader" class="preloader"><span class="spinner"></span></div>
@SashaKolbasov
SashaKolbasov / index.html
Last active March 27, 2017 16:56
Upload Photo/File
<label class="attach attachInput">
<span>Загрузите ваше фото</span>
<input type="file" name="photo" class="photo" accept="image/*" required />
</label>