Skip to content

Instantly share code, notes, and snippets.

(function(){
'use strict';
var width2 = 'data:image/gif;base64,R0lGODlhAgABAPAAAP///wAAACH5BAAAAAAALAAAAAACAAEAAAICBAoAOw==';
var width1 = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
var img = document.createElement('img');
var test = function(){
var width = img.width;
if(width == 2){
alert('your browser support sizes');
@aFarkas
aFarkas / pic.html
Last active September 13, 2015 20:44
pic
<picture>
<!--[if IE 9]><video style="display: none;"><![endif]-->
<source srcset="runner-wide.jpg" media="(min-width: 1000px)" />
<source srcset="runner-narrow.jpg" media="(min-width: 600px)" />
<!--[if IE 9]></video><![endif]-->
@aFarkas
aFarkas / maxres-.html
Created October 27, 2014 21:04
maxdpr
<!-
2x device and viewport 1000px: 2000.jpg (i.e.: 2dpr res)
3x device and viewport 1000px: 2000.jpg (i.e.: 2dpr res) <- constrained
3x device and viewport 1500px: 3000.jpg (i.e.: 2dpr res) <- constrained
->
<img srcset="500.jpg 500w, 1000.jpg 1000w, 1500.jpg 1500w, 2000.jpg 2000w, 3000jpg 3000w, 4000jpg 4000w" maxdpr="2" sizes="100vw" />
@aFarkas
aFarkas / maxres.html
Last active August 29, 2015 14:08
add maxdpr option
<!-- if you have 3dpr choose logo3x.png -->
<img src="logo.png" srcset="logo2x.png 200w, logo3x.png 300w" sizes="100px" />
<!--
if you have 3dpr and sizes computes to 100px choose img2.jpg
but if you have 2dpr and sizes computes to 150px take img3.jpg
-->
<img src="img.jpg" srcset="img2.jpg 200w, img3.jpg 300w" maxdpr="2" sizes="100px" />
<img src="logo.png" srcset="logo2x.png 200w, logo3x.png 300w" />
var timer;
var run = function(){
runpictureFill();
if(document.readyState == 'complete'){
clearInterval(timer);
}
};
timer = setInterval(run, 250);
setTimeout(run, document.body ? 9 : 99);
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
var onreadys = function(){
console.log(document.readyState);
console.log(document.body);
(function () {
var
documentElement = document.documentElement,
viewportFontSize, viewportHeight, viewportIsPortrait, viewportMax, viewportMin, viewportWidth;
function getViewportFontSize() {
var
body = documentElement.appendChild(document.createElement('body')),
iframe = document.createElement('iframe'),
iframeDocument;