This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function(){ | |
var tab = document.getElementsByTagName('table'); | |
tab[0].className = 'table table-hover'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Для Safari (iPhone / IPod / IPad) и Android браузера | |
<meta name="format-detection" content="telephone=no"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CSS | |
pointer-events:none | |
or jQuery | |
$('.overlay').click(function(e){ | |
$(".target").trigger(e); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test | |
test | |
test | |
test |