3

I have a map that is 930px x 530px. I want to use a mixin to convert the lat/long coords to top/left percentage values inside the box.

This is what i have so far...

@mixin latLong ($lat, $long) {
    left: (($long + 180) * (930/360)) + %;
    top: (($lat + 90) * (530/180)) + %;
}

I use it like this...

&.m1 {@include latLong(-33.94628333, 151.2157139);}

This is spitting out a value, but it's in quotes, so it's invalid to css. What am I doing wrong? Thanks.

cimmanon
  • 67,211
  • 17
  • 165
  • 171
Steven
  • 406
  • 4
  • 11

2 Answers2

13

You want to use multiplication to apply a unit, rather than concatenation:

@mixin latLong ($lat, $long) {
  left: (($long + 180) * (930/360)) * 1%;
  top: (($lat + 90) * (530/180)) * 1%;
}
cimmanon
  • 67,211
  • 17
  • 165
  • 171
8

Try using the native SASS helper method for percentages: http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#percentage-instance_method.

@mixin latLong ($lat, $long) {
    left: percentage(($long + 180) * (930/360));
    top: percentage(($lat + 90) * (530/180));
}
imjared
  • 19,492
  • 4
  • 49
  • 72