1.1.0 • Published 6 days ago

cube-3d-js v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

cube-3d-js

npm version License

ko-fi

Provides a 3D cube carousel display with perspective.

Installation

You can install this library using npm:

npm install cube-3d-js

Usage

HTML

<body>
  <div id="cube-3d">
    <div><h1>1</h1></div>
    <div><h1>2</h1></div>
    <div><h1>3</h1></div>
  </div>
  <style>
    #cube-3d-base > div {
      box-sizing: border-box;
      border: 0.5px solid black;
      color: blue;
      background-color: rgb(255 255 255 / 0.5);
    }
  </style>
</body>

JavaScript

import { init, onRotate, getFaceByIndex } from "cube-3d";

// Initialize the library with optional configuration
init("cube-3d", {
  width: 500,
  height: 500,
  initialRotation: 0,
});

// Register a callback for when the rotation changes
onRotate((currentFaceIndex: number, previousFaceIndex: number) => {
  // Your callback logic here
  console.log(
    `Face index changed from: ${previousFaceIndex} to: ${currentFaceIndex}`,
  );
});

// Retrieve a specific face element by index
const faceElement = getFaceByIndex(1);

API Documentation

init(targetId: string, config?: Cube3DConfig)

Initializes the application with optional configuration parameters.

  • targetId (string, optional): The ID of the target element (default is cube-3d).
  • config (object, optional): Optional configuration object for width, height, baseId, initialRotation, intensity, scrollIntensity, and swipeIntensity.

Config

Property NameDescriptionDefault Value
widthSets the width.500
heightSets the height.500
baseIdSets the baseElement ID.cube-3d-base
initialRotationSets the initial rotation degree.0
intensitySets the intensity of light.0.2
scrollIntensitySets the intensity of light on scroll.1.5
swipeIntensitySets the intensity of light on swipe.75

onRotate(callback: (currentFaceIndex: number, previousFaceIndex: number) => void)

Registers a callback function to be executed when the rotation changes.

  • callback (function): A function to call when the rotation changes with the detected face index and the previous face index.

getFaceByIndex(index: number): HTMLElement

Retrieves a specific face element by its index.

  • index (number): The index of the face element to retrieve.
  • Returns: The element corresponding to the specified index.

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.1.0

6 days ago

1.0.36

10 days ago

1.0.35

10 days ago

1.0.33

1 month ago

1.0.32

1 month ago

1.0.29

2 months ago

1.0.28

2 months ago

1.0.27

2 months ago

1.0.31

2 months ago

1.0.26

3 months ago

1.0.25

3 months ago

1.0.24

3 months ago

1.0.23

3 months ago

1.0.22

4 months ago

1.0.21

4 months ago

1.0.19

4 months ago

1.0.20

4 months ago

1.0.18

4 months ago

1.0.17

4 months ago

1.0.16

4 months ago

1.0.15

4 months ago

1.0.14

5 months ago

1.0.13

5 months ago

1.0.9

5 months ago

1.0.11

5 months ago

1.0.10

5 months ago

1.0.12

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago