Created
March 16, 2013 13:55
-
-
Save kazu69/5176499 to your computer and use it in GitHub Desktop.
mediaqueryで最適な画像に切り替えるサンプル refs: https://speakerdeck.com/smashingmag/responsive-web-design-clever-tips-and-techniques
This file contains hidden or 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
@media all and (min-width:45em) { | |
body:after { | |
content: 'desktop'; | |
display: none; | |
} |
This file contains hidden or 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
<a href='#'> | |
<img src='desktop-friendly-version.jpg' data-medium='tablet-friendly-version.jpg' data-large='desktop-friendly-version.jpg'> | |
</a> |
This file contains hidden or 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
$(function(){ | |
var size = window.getComputedStyle(document.body, ':after').getPropertyValue('content'); | |
if(size == 'desktop') { | |
$('img').each(function(index){ | |
$(this).attr( | |
src: $(this).attr('data-large'); | |
); | |
}); | |
} | |
if(size == 'tablet') { | |
$('img').each(function(index){ | |
$(this).attr( | |
src: $(this).attr('data-medium'); | |
); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment