Skip to content

Instantly share code, notes, and snippets.

View overstrides's full-sized avatar

Oleksandr Shut overstrides

View GitHub Profile
// Find all YouTube videos
var $allVideos = $("iframe[src*='//www.youtube.com']"),
// The element that is fluid width
$fluidEl = $(".main-content");
// Figure out and save aspect ratio for each video
$allVideos.each(function() {
$(this)
.data('aspectRatio', this.height / this.width)
// and remove the hard coded width/height
.removeAttr('height')
The HTML
The HTML code sets the YouTube video ID, styles the video size (width and height), and lists the Youtube URL parameters if needed.
The CSS
In the two videos used as examples, the picture ratio is 16:9, which returns the sddefault.jpg thumbnail with horizontal black bands. To hide them when showing this thumbnail, the background-position property is set with the center value, while setting the picture size inlined in the HTML div tag, like style="width:500px;height:281px;". This way, it is possible to show different video sizes on the same page.
The play icon, which tells the users the content is not a mere picture, is added in a layer on top of the thumbnail with an opacity transition to highlight it. We are using a data URI base64-encoded png here (from IconFinder), which saves an HTTP request and works down to IE8.
Vanilla JavaScript Implementation
With no dependency and the fastest implementation, the vanilla JavaScript version uses the smallest DOM ready code I could find.
@overstrides
overstrides / gist:198c97ce6582fb82b61767ff4248ed2d
Created August 8, 2016 11:43
find table and add a class via js
window.onload = function(){
var tab = document.getElementsByTagName('table');
tab[0].className = 'table table-hover';
}
var element = document.getElementById('sidebar');
var trigger = document.getElementById('js-toggle-sidebar'); // or whatever triggers the toggle
trigger.addEventListener('click', function(e) {
e.preventDefault();
element.classList.toggle('sidebar-active'); // or whatever your active class is
});
@overstrides
overstrides / Отключение преобразования телефонных номеров в ссылки Как отключить преобразование телефонных номеров в ссылки в мобильных браузерах
Для Safari (iPhone / IPod / IPad) и Android браузера
<meta name="format-detection" content="telephone=no">
@overstrides
overstrides / 0_reuse_code.js
Created April 10, 2016 21:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@overstrides
overstrides / gist:7fe7d0957e2c6972c99a
Created March 3, 2016 09:29
Scroll-menu in header
jQuery
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if ( (scroll >= 100) && ($(window).width() > '991') ) {
$(".b-scrollHeader").addClass("js-show");
} else {
$(".b-scrollHeader").removeClass("js-show");
}
});
@overstrides
overstrides / gist:17bee14266692e5d7965
Last active March 3, 2016 08:27
Прозрачный для кликов мышкой блок
CSS
pointer-events:none
or jQuery
$('.overlay').click(function(e){
$(".target").trigger(e);
});
test
test
test
test