Search code examples
javascriptsasscompass

Javascript wheel dynamic abilities


I came across this wheel script that I'd like to possibly implement. However, I need the $ of wheel panels to be dynamic. The SASS had a variable in it already, but if I modify it to say 20, and add more div elements, the wheel still only shows 10. It looks like the mixins that calculate the angle use the $num-sides variable. I do see extra elements when it first loads, but they disappear as soon as the wheel is touched. What am I missing?

http://codepen.io/Aldlevine/pen/yGLqd

$num-wheels: 1;
$num-sides: 20;
$wheel-height: 10rem;

Solution

  • There's one more place where 10 existed and should change to 20 (see the comment in the code below):

    $('.wheel').momentus({
      u: 1,
      mass: 1000,
      wheelRatio: -1000,
      mouseRatio: 6,
      onChange: function(coords, velocity){
        console.log('update');
        $('.wheel > div').each(function(i){
          var angle = -(coords.y/2) + (360/20)*i; // <-- CHANGE 10 to 20 HERE
          $(this).css('transform', 'perspective(500px) rotate3d(1,0,0,'+angle+'deg) translate3d(0,0,122px)');
        });
      }
    });
    

    If you run it with only that change, the panels in the wheel are far too large. In order for it to look good, you should also halve the $wheel-height to 5rem.