Skip to content

Instantly share code, notes, and snippets.

View jamenlyndon's full-sized avatar

Jamen Lyndon jamenlyndon

View GitHub Profile
@jamenlyndon
jamenlyndon / index.html
Created September 9, 2015 05:58
Resize at aspect ratio with pure CSS
<div class='container'>
<iframe src='video.mp4' frameborder='0'></iframe>
</div>
<style type='text/css'>
.container {
position: relative;
width: 100%;
@jamenlyndon
jamenlyndon / getVars.js
Last active August 29, 2015 14:27
Use GET vars with JS
// Read the GET variables
var $_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
function decode(s) {
return decodeURIComponent(s.split("+").join(" "));
}
$_GET[decode(arguments[1])] = decode(arguments[2]);
});
// Use the GET variables
@jamenlyndon
jamenlyndon / iframe.html
Last active December 28, 2023 04:30
Resize iframe height to fit content (works cross domain)
<script type='text/javascript' src="js/jquery.min.js"></script>
<script type='text/javascript'>
// Size the parent iFrame
function iframeResize() {
var height = $('body').outerHeight(); // IMPORTANT: If body's height is set to 100% with CSS this will not work.
parent.postMessage("resize::"+height,"*");
}
$(document).ready(function() {
// Resize iframe
@jamenlyndon
jamenlyndon / example.js
Last active August 29, 2015 14:26
Modify global CSS with JS
function css(selector, property, value) {
for (var i=0; i<document.styleSheets.length;i++) {
try { document.styleSheets[i].insertRule(selector+ ' {'+property+':'+value+'}', document.styleSheets[i].cssRules.length);
} catch(err) {try { document.styleSheets[i].addRule(selector, property+':'+value);} catch(err) {}}//IE
}
}
// Example usage:
css('.header', 'border', '5px solid green');
@jamenlyndon
jamenlyndon / example.js
Last active August 29, 2015 14:25
Check for IE (JS)
// Check for IE
// ------------------------------------------------
var ie = (function(){
var undef;
var v = 3;
var div = document.createElement('div');
var all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
@jamenlyndon
jamenlyndon / periscope.js
Last active September 9, 2015 06:00
Get data from periscope
// Convert CSV to JS Obj
function csvToObj(csv) {
var lines = csv.split("\n");
var result = [];
var headers = lines[0].split(",");
for (var i = 1; i < lines.length; i++) {
var obj = {};
var currentline = lines[i].split(",");
@jamenlyndon
jamenlyndon / scrollToAnchors.js
Created April 29, 2015 04:27
Scroll to anchors (jQuery)
// Scroll to anchors
$(document).ready(function() {
$("a[href^=#]").click(function(e) {
e.preventDefault();
var dest = $(this).attr('href').replace('#', '');
$('html,body').animate({ scrollTop: $('[name='+dest+']').offset().top }, 'slow');
});
});