Skip to content

Instantly share code, notes, and snippets.

@VicVicos
Last active May 4, 2018 07:51
Show Gist options
  • Select an option

  • Save VicVicos/dae60b5c2dd47e1a885decda599095f2 to your computer and use it in GitHub Desktop.

Select an option

Save VicVicos/dae60b5c2dd47e1a885decda599095f2 to your computer and use it in GitHub Desktop.
JSnippets
http://habrahabr.ru/post/211538/
https://habrahabr.ru/sandbox/91471/ - tabs
// Проверка на подключенный jQuery
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script>
// Плавный скролл к верху
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
// Плавный скрол к якорю.
$(".nav a").on('click', function(event) {
event.preventDefault();
var anchor = $(this).attr('href');
var toTop = $(anchor).offset();
$('html, body').animate({ scrollTop: toTop.top - 70 }, "slow");
return false;
});
// Скрол к якорю на другой странице
document.body.scrollTop = 0;
var scrolled = false;
$(document).one('ready scroll hashchange', function(e) {
if(scrolled != false || location.hash.length == 0) return;
e.preventDefault();
var name = location.hash.substr(1);
var el = $('#'+name+', [name='+name+']');
// console.log(el);
if(el.length)
{
$('html, body').animate({ scrollTop: el.offset().top - 200 }, "slow");
scrolled = true;
}
});
// Колонки одинаковой высоты
var maxheight = 0;
$("div.col").each(function() {
if($(this).height() > maxheight) { maxheight = $(this).height(); }
});
$("div.col").height(maxheight);
// Кнопка вверх
var lastScrollTop = 0;
$(window).scroll(function(event){
var st = $(this).scrollTop();
if (st > lastScrollTop){
if (st >= 350) {
$("a[href='#toTop']").fadeIn();
}
} else {
// вверх
if (st < 350) {
$("a[href='#toTop']").fadeOut();
}
}
lastScrollTop = st;
});
$("a[href='#toTop']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
var n=$(".container").offset().left;
$(".toTop").css("right",n/2);
// Добавляем свою функцию в jQuery
(function($) {
$.fn.boldFirstWord = function() {
console.log(1);
var str = this.text();
var splited = str.split(' ');
var replaced = str.split(splited[0]).join('<span class="bold">' + splited[0] + '</span>');
this.html(replaced);
};
})(jQuery);
// Вызов
$('.first-bold').each(function(index, el) {
$(this).boldFirstWord();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment