Skip to content

Instantly share code, notes, and snippets.

@Inontran
Inontran / get-width-scrollbar.js
Created July 17, 2020 08:31
получение ширины scrollbar
function get_width_scrollbar(){
$('body').append('<div class="get-scrollbar-width-js"></div>');
var $div = $('.get-scrollbar-width-js');
$div.css({
position: 'absolute',
bottom: '0',
left: '0',
zIndex: '-1000',
@Inontran
Inontran / fixed-page-modal-2.js
Created July 17, 2020 06:54
убирает padding справа у модальных окон bootstrap
$('body').on('show.bs.modal', '.modal', function(){
var scrollTop_body = $('html, body').scrollTop() || $(document).scrollTop() || $(window).scrollTop();
$('body').css({
top: '-' + scrollTop_body + 'px'
});
$('body').on('hidden.bs.modal', '.modal', function(){
$('body').css({
top: ''
});
@Inontran
Inontran / sticky-top.js
Last active August 1, 2020 06:20
sticky top на javascript
function sticky_top($block, $parent, top_padding){
try{
var block_H = $block.height();
var scrollTop_body = $('html, body').scrollTop() || $(document).scrollTop() || $(window).scrollTop();
if( !$parent ){
$parent = $block.parent();
}
var parent_H = $parent.height();
@Inontran
Inontran / swipe-scroll-x.js
Created July 13, 2020 02:25
свайп мышкой горизонтального скролла
// СВАЙП МЫШКОЙ ГОРИЗОНТАЛЬНОГО СКРОЛЛА -------------------
var $slider = $('.scroll.scroll_x .scroll__content');
var isDown = false;
var startX;
var scrollLeft;
$slider.mousedown(function(e){
isDown = true;
$slider.addClass('active');
startX = e.pageX - $slider.get(0).offsetLeft;
@Inontran
Inontran / init-jquery-scrollbar.js
Created July 10, 2020 01:40
создание скроллбара и отключение его в Firefox на Macbook
function init_scrollbar(){
try {
if(
window.navigator.userAgent.indexOf('Macintosh') != -1 &&
window.navigator.userAgent.indexOf('Firefox') != -1
){
$('.scrollbar').css('overflow', 'auto');
}
else{
$('.scrollbar').scrollbar({
@Inontran
Inontran / iframe-responsive.js
Created June 30, 2020 06:44
адаптивность iframe во время resize окна
if($('iframe').length > 0){
var kk = new Array;
$('iframe').each(function(index)
{
kk[index] = $(this).height() / $(this).width();
$(this).css('max-width', '100%');
$(this).css('height', $(this).width() * kk[index]);
});
@Inontran
Inontran / get-file-name.js
Created June 20, 2020 12:33
получение имени файла из пути до файла
function getFilename(path) {
return path.split('\\').pop().split('/').pop();
}
@Inontran
Inontran / collapse-inline.tpl
Created June 6, 2020 02:47
горизонтальный collapse с переносом на новую строку
<div class="row align-items-center collapse-inline-js d-none d-md-flex" data-count-rows="1">
<?php foreach ($data['category']->children as $key => $item): ?>
<div class="col-auto pb-2 pb-lg-3 collapse-el-js">
<a href="<?=$item->link?>" class="position-relative btn btn-transparent px-2 small-2">
<img src="<?=SITE?>styles/images/site/str_orange2.png" class="position-absolute"><?=$item->title?>
</a>
</div>
<?php endforeach; ?>
<div class="col-auto pb-2 pb-lg-3 more d-none">
<a href="#" class="collapse-inline-toggle-js" data-option="showCollapseInline">
@Inontran
Inontran / collapse-inline.js
Created June 6, 2020 02:44
горизонтальный collapse с переносом на новую строку
$('body').find('.collapse-inline-js').each(function(){
$(this).inlineCollapse();
});
var timer_collpase_inline = null;
$(window).resize(function(){
if( timer_collpase_inline !== null ){
clearTimeout(timer_collpase_inline);
}
@Inontran
Inontran / lazyload-video.js
Created June 4, 2020 08:36
lazyload видео
$('video').each(function () {
if ($(this).attr('data-source')) {
var sources = $(this).attr('data-source');
// console.log(sources);
var ext = sources.split('.')[1];
var html = '<source src="' + sources + '" type=\'video/' + ext;
if (codecs[ext])
html += '; codecs="' + codecs[ext] + '"\'';
else