Created
June 29, 2012 14:53
-
-
Save lazd/3018429 to your computer and use it in GitHub Desktop.
Working version of designermonkey's at2x mixin from cloudhead/less.js bug #843
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>less.js bug #843: working at2x mixin</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | |
</head> | |
<body> | |
<link rel="stylesheet/less" type="text/css" href="styles.less"> | |
<script src="http://lesscss.googlecode.com/files/less-1.3.0.min.js" type="text/javascript"></script> | |
<div id="cow"></div> | |
</body> | |
</html> |
This file contains 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
/* Mixin with quoted path in URL */ | |
.at2x(@path, @w: auto, @h: auto) { | |
background-image: url('@{path}'); | |
@at2x_path: ~`"@{path}".split('.').slice(0, "@{path}".split('.').length - 1).join(".") + "@2x" + "." + "@{path}".split('.')["@{path}".split('.').length - 1]`; | |
@media all and (-webkit-min-device-pixel-ratio : 1.5) { | |
background-image: ~"url(@{at2x_path})"; | |
background-size: @w @h; | |
} | |
} | |
/* Class using mixin */ | |
div#cow { | |
width: 150px; | |
height: 196px; | |
.at2x('cow.png', 150px, 196px); | |
background-repeat: no-repeat; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment