Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

3d-rotater-y

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3d-rotater-y

Resolve like 3D badge rotation controls.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

针对 3D 徽章的预览提供简单的控制能力:通过手指或鼠标控制徽章旋转角度、松手后自动保持水平位置。

Install

$ npm i 3d-rotater-y --save

3d-rotater-y

Features

  • 🚀 动画更新基于requestAnimationFrame
  • 🧭 仅支持 Y 轴方向旋转控制;
  • 🪆 需要附带“根据不同范围内的旋转角度,能够自动过渡到水平位置”的惯性/重力感旋转效果;(从平面视角来看,需要达到[0,90),松手后回到 0 弧度位置;(90,180],松手后回到 PI 弧度位置的旋转过度效果)
  • 👬 同时支持 PC 和移动端;
  • 从指定角度开始归零的旋转过渡动画;
  • 支持初始化时制定任意展示角度;
  • 点击/双击回到初始角度;

Usage

basic
import rotateCtrl from "3d-rotater-y";

/**
* RotateControl(targetDom, targetRadius);
* targetDom 需要控制的元素
* targetRadius 目标元素的半径(宽度的一半,影响手指或鼠标滑动元素时的敏感度),默认200px

  returns {
    rad:Number, //弧度值
    onTouch:Boolean, //是否正在操作被控目标
}
*/

let targetDom = document.querySelector("#badge_stage");
let rotateCtrl = new RotateControl(targetDom);
let isTouching = false;
// 添加监听事件,目前只有一个`update`事件可供监听,并在回调内更新「徽章badgeMesh.rotation.y」
rotateCtrl.on(
  "update",
  ({ rad, onTouch, positiveRad, speed, startRad, endRad }) => {
    isTouching = onTouch;
    badgeMesh && (badgeMesh.rotation.y = rad);
  }
);

// 开始监听旋转控制返回的数据
rotateCtrl.listen();
Advance
/**
* rotateCtrl.reset(duration, resetRad);
* duration 过渡时间ms,默认500
* resetRad 制定重置的角度,默认0
*/

// 比如想在1000ms里,从PI开始重置到0,可以这么用!
rotateCtrl.reset(0, PI);
rotateCtrl.reset(1000, 0);
Todos
  • 模拟 Apple Watch 徽章松手后的摆动->停止的过渡效果
  • 完成freezePage函数:手指/鼠标控制目标元素转动时,禁止页面 scrollY
  • 删除playAmt函数:第一个版本,能够实现小摆动,但是停住的时机不够精准;

Keywords

FAQs

Package last updated on 26 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc