How to use the @mathigon/boost.Browser.isMobile function in @mathigon/boost

To help you get started, we’ve selected a few @mathigon/boost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathigon / textbooks / content / shared / components / solid.ts View on Github external
function rotate($solid: Solid, animate = true, speed = 1) {
  // TODO Damping after mouse movement
  // TODO Better mouse-to-point mapping

  // Only Chrome is fast enough to support auto-rotation.
  const autoRotate = animate && Browser.isChrome && !Browser.isMobile;

  let dragging = false;
  let visible = false;

  function frame() {
    if (visible && autoRotate) requestAnimationFrame(frame);
    $solid.scene.draw();
    if (!dragging) $solid.object.rotation.y += speed * 0.012;
  }

  if (autoRotate) {
    $solid.scene.$canvas.on('enterViewport', () => { visible = true; frame(); });
    $solid.scene.$canvas.on('exitViewport', () => { visible = false; });
  } else {
    setTimeout(frame);
  }