Skip to content

Instantly share code, notes, and snippets.

@lazd
Created June 29, 2012 14:53
Show Gist options
  • Save lazd/3018429 to your computer and use it in GitHub Desktop.
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
<!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>
/* 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