<html>
<head>
<meta charset=utf-8 />
<title>Responsive Images using Dynamic Base URL</title>
<base href="http://placehold.it/1024/FF0000/">
<script>
(function(){
var assetPath = 'http://placehold.it/';
if( screen.width < 480 ){
assetPath += '240/';
}
else if( screen.width < 960 ){
assetPath += '480/';
}
else if( screen.width < 1024 ){
assetPath += '960/';
}
else {
assetPath += '1024/';
}
assetPath += '00FF00/';
document.getElementsByTagName('base')[0].href = assetPath;
})();
</script>
<style>
.pass { color:green; }
.pass:after { content:" (pass)"; }
.fail { color:red; }
.fail:after { content:" (fail)"; }
</style>
</head>
<body>
<h1>Responsive Images using Dynamic Base URL</h1>
<p>Proof of concept for <a href="http://blog.keithclark.co.uk/responsive-images-using-cookies/#comment-16">Schepp's comment</a> on Keith Clark's <a href="http://blog.keithclark.co.uk/responsive-images-using-cookies/">Responsive images using cookies</a>. No cookies needed!!!</p>
<p>Image src: <span id=src>Loading…</span></p>
<img src="FFF.png&text=ResponsiveImage">
</body>
</html>
window.onload = function(e){
var srcEl = document.getElementById('src');
srcEl.textContent = document.images[0].src;
srcEl.className += src.textContent.indexOf('00FF00') != -1 ? 'pass' : 'fail';
};
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |