How to show wind direction on a compass

AL̲̳I picture AL̲̳I · Jul 17, 2012 · Viewed 10.7k times · Source

I am working on a web application where I have to show the temperature, humidity, wind speed, wind direction etc. I am using google.visualization.Gauge() to show other things but I want to show wind direction on a compass. Does anyone know about any (jQuery/javascript/etc) compass available that I can use for a website/webapp? Thanks

Answer

sachleen picture sachleen · Jul 17, 2012

Here's my approach using only CSS. Uses transforms to rotate the needle. DEMO You can also use the jQuery Rotate plugin.

HTML

<div id="compass">
  <div id="arrow"></div>
</div>​

CSS

#compass {
  width: 380px;
  height: 380px;
  background-image:url('http://i.imgur.com/44nyA.jpg');
  position: relative;
}
#arrow {
  width: 360px;
  height: 20px;
  background-color:#F00;
  position: absolute;
  top: 180px;
  left: 10px;
  -webkit-transform:rotate(120deg);
  -moz-transform:rotate(120deg);
  -o-transform:rotate(120deg);
  -ms-transform:rotate(120deg);

  -moz-transition: all 1s ease;
  -webkit-transition: all 1s ease;
  -o-transition: all 1s ease;
  transition: all 1s ease;
}

#compass:hover #arrow {
  -webkit-transform:rotate(0deg);
  -moz-transform:rotate(0deg);
  -o-transform:rotate(0deg);
  -ms-transform:rotate(0deg);
}​