生成和操作 CSS 3D 转换效果的库:Sprite3D.js

jopen 11年前

Sprite3D.js 是生成和操作 CSS 3D 转换效果的库。Sprite3D.js 没有任何的依赖项,所以非常容易集成 JS 库。Sprite3D.js 使用简单的 JavaScript 语法来控制 3D 转换效果。浏览器支持 Chrome, Safari, iOS, Android 4, BlackBerry, Firefox 10 和 Internet Explorer 10。

参考

请参考源代码中的注释,了解有关如何使用这些方法的更详细的说明。

Static methods

  • Sprite3D.isSupported() - check support for CSS 3D transforms
  • Sprite3D.stage() - create a root node to use as a main container
  • Sprite3D.create() - creates a new Sprite3D div element
  • Sprite3D.box() - creates a box (i.e. a cube)

Instance methods

Position

  • x() - get/set the x position
  • y() - get/set the y position
  • z() - get/set the z position
  • position() - set the x, y and z position
  • move() - adds the provided values to the current position

Rotation

  • rotationX() - get/set the rotation around the X axis
  • rotationY() - get/set the rotation around the Y axis
  • rotationZ() - get/set the rotation around the Z axis
  • rotation() - set the rotation around all axis
  • rotate() - adds the provided values to the current rotation

Scale

  • scaleX() - get/set the scale around the X axis
  • scaleY() - get/set the scale around the Y axis
  • scaleZ() - get/set the scale around the Z axis
  • scale() - set the scale for all axis.

Hierarchy

  • appendChild() and removeChild() - just kidding, these are the native methods of the HTML elements (and remember, the Sprite3D object IS the HTML element)

Helper functions

  • origin() - specifies the registration point of the element (default is top-left corner)
  • transformOrigin() - specifies the pivot around which the element is rotated and scaled (default is center)
  • transformString() - lets you decide the order of the transformations
  • perspective() - sets the amount of perspective (mainly useful for the stage, default is 800px)
  • css() - chainable shorthand for setting a CSS value in the style property
  • addClass() and removeClass() - chainable wrappers for the native classList.add() and classList.remove()
  • html() - chainable shorthand for the innerHTML property of the element
  • size() - chainable shorthand for setting both style.width and style.height
  • bind() and unbind() - chainable shorthand for addEventListener and removeEventListener methods, allows to pass multiple events and callbacks
  • tileSize() and tilePosition() - basic spritesheet support
  • set() - generic chainable setter/getter

项目主页:http://www.open-open.com/lib/view/home/1400826906268