Socket
Socket
Sign inDemoInstall

@3dweb/360javascriptviewer

Package Overview
Dependencies
8
Maintainers
1
Versions
140
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@3dweb/360javascriptviewer

A 360 javascript viewer working with images


Version published
Maintainers
1
Weekly downloads
410
decreased by-12.21%

Weekly downloads

Readme

Source

360 Javascript Viewer

A flexible light responsive 360 image viewer with zoom functions. You can use it with npm (typescript support) or include the script on your page. Autorotate, batch loading of images, inertia and speed control. Events for making custom progress bars, intro animations and custom zoom functions. Several methods for navigation from outside which return promises for easy chaining of actions. Use all kind of images from any location with flexible start numbering and filenames.

Check for examples on 360-javascriptviewer.com
Check for cloud solution on 3DWeb.io

Installation

using npm with typescript declaration file:

npm i @3dweb/360javascriptviewer

import {JavascriptViewer} from "@3dweb/360javascriptviewer";

or use the CDN to get the latest version

<script src="https://unpkg.com/@3dweb/360javascriptviewer"></script>

Basic usage

First create a div where the 360 presentation will be created. We use the size of this div to calculate zoom positions. The events for dragging and zooming are also added to this div (default #jsv-holder). Insert a image in it which is often the first image of the 360 image serie. This image will be replaced by the 360 presentation when it's fully loaded. If you don't specify otherwise this image is used to determine the other image filenames. If the main image is product.jpg, the other images in the same folder must be called product_1.jpg, product_2.jpg and so on. But if you have other filenames/locations for your 360 images, you can change this naming format behaviour with the imageUrlFormat parameter.

    <div id="jsv-holder">
        <img id="jsv-image" alt="example" src="https://360-javascriptviewer.com/images/ipod/ipod.jpg">
    </div>
    
    <script>                    
        const viewer = new JavascriptViewer({
            mainHolderId: 'jsv-holder',
            mainImageId: 'jsv-image',
            totalFrames: 72,
            speed: 70,
            defaultProgressBar: true
        });
        
        // use events for example
        viewer.events().loadImage.on((progress) => {
            // use this for your own progress bar    
            console.log(`loading ${progress.percentage}%`)
        })           
         
         viewer.events().started.on((result) => {
            // use a promise or a start event to trigger things    
        })
        
         viewer.start().then(() => {
            viewer.rotateDegrees(180).then(() => {
                // continue with your amazing intro
            })
        });
    </script> 
    

API

Constructor

propertytypedescriptiondefault
idstringID of the presentation created by 3dweb.iojsv-image
mainImageIdstringID of the image which is the base for all the frames. You can also use mainImageUrl if the path of the other files are different.jsv-image
mainHolderIdstringID of the div where the presentation runs in.jsv-holder
mainImageUrlstringURl of the first image, doesn't have to be in the document. Not needed when using imageUrls
totalFramesnumberAmount of frames in the presentation, more images means smoother rotations.72
imageUrlsstring[]Array of image urls, overrides totalFrames and imageUrlFormat[]
firstImageNumbernumberAfter loading the presentation this is the first frame visible.1
reversebooleanInvert the rotation direction when dragging.false
speednumberSpeed of rotating. -199 to 10080
inertianumberDelay when stop dragging.20
defaultProgressBarbooleanDisable the build in progress bar, use this when you have implemented your own loader or don't like this one.true
imageUrlFormatstringFormat for determining the filenames of the frames {filename}_xx.{extension} is the default ipod_x.jpg => ipod_1.jpg ipod_xx.jpg => ipod_01.jpg https://other.cdn/images/ipod_xx.jpg => https://other.cdn/images/ipod_01.jpg{filename}_xx.{extension}
extraImageClassstringAdd a class to all the images used in the presentation, separate multiple classes with a space.empty
startFrameNonumberUse this setting in combination with imageUrlFormat startFrameNo: 4 => first file is ipod_04.jpg1
autoRotatenumberUse this setting for rotating the view at start. Rotation stops when user drags the model or another animation method is called.0
autoRotateSpeednumberSpeed of autorotation. -199 to 1001
autoRotateReversebooleanUse this setting for changing the direction of the auto rotating.1
enableImageEventsbooleanUse this setting for enabling click pinch and wheel events on images.0
zoombooleanUse this setting for enabling zoom functions. Zoom on wheel event or pinch.0
zoomWheelSpeednumberChange the speed of zooming with the mousewheel.50
zoomMaxnumberIf zoom is enabled this is the max zoom factor.2
stopAtEdgesbooleanBlocks repeating images after reaching last image.0
autoCDNResizerbooleanSet the query params height and width for use with an image resizer.0
autoCDNResizerConfigIAutoCDNResizerConfigConfig for adding query params to image urls.0
enableChangeImageEventbooleanEnable changeImage event on rotation, could be CPU heavy0
cursorConfigICursorConfigChange the cursors for the presentation
notificationConfigInotificationConfigConfigure the default notifications

Methods

  • start():Promise
    Start the presentation, loading all images and replace the main image with a 360 presentation.
  • destroy():Promise
    Destroys the presentation and returns to previous state-
  • setId(id: string):Promise
    Destroys the presentation and creates the presentation again with the new ID. Only for presentations in 3dweb.io
  • rotateDegrees(degree: number):Promise
    Set the desired rotation and the 360 model is rotating to it.
  • rotateToDegree(targetDegree: number, shortestWay?: boolean, useEasing?: boolean)):Promise
    Rotate to a certain degree. Frame nr 1 is 0 degrees.
  • rotateToFrame(frame: number, shortestWay?: boolean, useEasing?: boolean)):Promise
    Rotate to a certain frame.
  • setSpeed(speed:number):void Zoom and pan in the image.
  • zoomTo(factor: number, x: number, y: number):Promise
    Zoom with a factor and pan in percentage from the middle -1-0 and 0-1.
  • setInertia(inertia:number):void
    Set the current inertia of the viewer
  • events():IEvents
    Use this to register events.-
    isZoomedIn():boolean Checks if the presentation is zoomed.

Events

  • loadImage:IProgress Use this event to create your own progress bar
    viewer.events().loadImage.on((progress) => { // use the progress object for your own loader })

  • started:boolean Use this event to trigger other actions when the viewer is ready
    viewer.events().started.on((boolean) => { // start intro animations or other creative ideas })

  • startDragging:IHandle Use this event to capture the user drag movement. viewer.events().startDragging.on((handle) => { // show or hide information on the viewer or send statistics })

  • changeImage:IStatus Fires when a new image becomes visible, works in combination with enableChangeImageEvent:true viewer.events().changeImage.on((handle) => { // show or hide information on the viewer or send statistics })

  • endAutoRotate:IStatus Fires when autorotate stops viewer.events().endAutoRotate.on((status) => { // show or hide information on the viewer or send statistics })

  • click:IClick Fires when the user clicks on a image, works in combination with enableImageEvents: true viewer.events().click.on((click) => { // Use this event for zoom functions })

  • pinch:IPinch Fires when the user pinch on a image (zoom on mobile with 2 fingers), works in combination with enableImageEvents: true viewer.events().pinch.on((click) => { // Use this event for zoom functions })

  • scroll:IScroll Fires when the user use the mouse scroll, works in combination with enableImageEvents: true viewer.events().pinch.on((click) => { // Use this event for zoom functions })

  • doubleClick:IClick Fires when the user double clicks on a image, works in combination with enableImageEvents: true viewer.events().pinch.on((click) => { // Use this event for zoom functions })

Interfaces

  • IResponse {
      currentDegree: number;
    }

  • IAutoCDNResizerConfig {
      useWidth: boolean;
      useHeight: boolean; //default true
      scaleWithZoomMax: boolean; //default false loads images with the zoomMax factor for height or width
    }

  • notificationConfig {
      dragToRotate: {
       showStartToRotateDefaultNotification: boolean,
       imageUrl: string,
       languages: ITranslation[],
       mainColor: string //hex,rgb or rgba color
       textColor: string //hex,rgb or rgba color
      }
    }

  • ITranslation { [
      language: string, //ISO Language Code (en-US,nl-NL)
      text: string
    ]}

  • IStatus {
      currentDegree: number;
      currentImage: IImage;   completed: boolean; }

  • IImage {
      id: string;
      src: string;   sequence: number; }

Keywords

FAQs

Last updated on 03 Sep 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc