You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
773 B

10 years ago
  1. // To make images retina, add a class "2x" to the img element
  2. // and add a <image-name>@2x.png image. Assumes jquery is loaded.
  3. function isRetina() {
  4. var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
  5. (min--moz-device-pixel-ratio: 1.5),\
  6. (-o-min-device-pixel-ratio: 3/2),\
  7. (min-resolution: 1.5dppx)";
  8. if (window.devicePixelRatio > 1)
  9. return true;
  10. if (window.matchMedia && window.matchMedia(mediaQuery).matches)
  11. return true;
  12. return false;
  13. };
  14. function retina() {
  15. if (!isRetina())
  16. return;
  17. $("img.2x").map(function(i, image) {
  18. var path = $(image).attr("src");
  19. path = path.replace(".png", "@2x.png");
  20. path = path.replace(".jpg", "@2x.jpg");
  21. $(image).attr("src", path);
  22. });
  23. };
  24. $(document).ready(retina);