@3dweb/360javascriptviewer 中文文档教程
360 Javascript Viewer
具有缩放功能的灵活的光响应 360 度图像查看器。 您可以将它与 npm 一起使用(打字稿支持) 或在您的页面上包含脚本。 自动旋转、图像批量加载、惯性和速度控制。 用于制作自定义进度条、介绍动画和自定义缩放功能的事件。 几种从外部导航的方法返回易于链接操作的承诺。 通过灵活的起始编号和文件名使用来自任何位置的各种图像。
在 360-javascriptviewer.com 上查看示例
Installation
使用带有打字稿声明文件的 npm
npm i @3dweb/360javascriptviewer
import {JavascriptViewer} from "@3dweb/360javascriptviewer";
:或使用 CDN 获取最新版本
<script src="https://unpkg.com/@3dweb/360javascriptviewer"></script>
Basic usage
首先创建一个 div,其中将创建 360 度演示文稿。 我们用这个div的大小来计算 缩放位置。 拖动和缩放的事件也被添加到这个 div(默认#jsv-holder)。 在其中插入一张图像,这通常是 360 图像系列的第一张图像。 此图片将替换为 满载时的 360 度演示。 如果您没有另外指定,则此图像用于确定其他图像文件名。 如果主图是product.jpg,那么同一个文件夹下的其他图片必须叫product1.jpg、product2.jpg等等。 但是,如果您的 360 度图像有其他文件名/位置,则可以使用 imageUrlFormat 参数更改此命名格式行为。
<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
property | type | description | default |
---|---|---|---|
mainImageId | string | ID of the image which is the base for all the frames. You can also use mainImageUrl | jsv-image |
mainHolderId | string | ID of the div where the presentation runs in. | jsv-holder |
mainImageUrl | string | URl of the first image, doesn't have to be in the document. mainImageId is not necessary with this option | |
totalFrames | number | Amount of frames in the presentation, more images means smoother rotations. | 72 |
imageUrls | string[] | Array of image urls, overrides totalFrames and imageUrlFormat | [] |
firstImageNumber | number | After loading the presentation this is the first frame visible. | 1 |
reverse | boolean | Invert the rotation direction when dragging. | false |
speed | number | Speed of rotating. -199 to 100 | 80 |
inertia | number | Delay when stop dragging. | 20 |
defaultProgressBar | boolean | Disable the build in progress bar, use this when you have implemented your own loader or don't like this one. | true |
imageUrlFormat | string | Format for determining the filenames of the frames {filename}xx.{extension} is the default ipodx.jpg => ipod1.jpg ipodxx.jpg => ipod01.jpg https://other.cdn/images/ipodxx.jpg => https://other.cdn/images/ipod_01.jpg | {filename}_xx.{extension} |
startFrameNo | number | Use this setting in combination with imageUrlFormat startFrameNo: 4 => first file is ipod_04.jpg | 1 |
autoRotate | number | Use this setting for rotating the view at start. Rotation stops when user drags the model or another animation method is called. | 1 |
autoRotateSpeed | number | Speed of autorotation. -199 to 100 | 1 |
autoRotateReverse | boolean | Use this setting for changing the direction of the auto rotating. | 1 |
enableImageEvents | boolean | Use this setting for enabling click pinch and wheel events on images. | 0 |
zoom | boolean | Use this setting for enabling zoom functions. Zoom on wheel event or pinch. | 0 |
zoomWheelSpeed | number | Change the speed of zooming with the mousewheel. | 50 |
zoomMax | number | If zoom is enabled this is the max zoom factor. | 2 |
stopAtEdges | boolean | Blocks repeating images after reaching last image. | 0 |
autoCDNResizer | boolean | Set the query params height and width for use with an image resizer. | 0 |
enableChangeImageEvent | boolean | Enable changeImage event on rotation, could be CPU heavy | 0 |
cursorConfig | ICursorConfig | Change the cursors for the presentation | |
notificationConfig | InotificationConfig | Configure 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 - 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
加载图片:IProgress 使用此事件创建您自己的进度条
viewer.events().loadImage.on((progress) => { // 为你自己的加载器使用进度对象 })
开始:boolean 当查看器准备就绪时,使用此事件触发其他操作
viewer.events().started.on((boolean) => { // 开始介绍动画或其他创意 })
开始拖动:IHandle 使用此事件捕获用户拖动动作。
viewer.events().startDragging.on((handle) => { // 显示或隐藏有关查看器的信息或发送统计信息 })
changeImage:IStatus 当新图像变得可见时触发,与 enableChangeImageEvent:true 结合使用
viewer.events().changeImage.on((handle) => { // 显示或隐藏有关查看器的信息或发送统计信息 })
endAutoRotate:IStatus 当自动旋转停止时触发
viewer.events().endAutoRotate.on((status) => { // 显示或隐藏有关查看器的信息或发送统计信息 })
点击:IClick 当用户点击图像时触发,与 enableImageEvents 结合使用:true <代码>viewer.events().click.on((click) => { // 将此事件用于缩放功能 })
捏:IPinch 当用户在图像上捏合时触发(用 2 根手指在移动设备上缩放),与 enableImageEvents 结合使用:true
viewer.events().pinch.on((click) => { // 将此事件用于缩放功能 })
滚动:IScroll 当用户使用鼠标滚动时触发,与 enableImageEvents 结合使用:true
viewer.events().pinch.on((click) => { // 将此事件用于缩放功能 })
doubleClick:IClick 当用户双击图像时触发,与 enableImageEvents 结合使用:true
viewer.events().pinch.on((click) => { // 将此事件用于缩放功能 })
Interfaces
IResponse {
当前学位:数字;
}notificationConfig {
dragToRotate: {
showStartToRotateDefaultNotification:布尔值,
imageUrl: 字符串,
语言:ITranslation[],
mainColor: string //十六进制、rgb 或 rgba 颜色
textColor: string //十六进制、rgb 或 rgba 颜色
}ITranslation { [
language: string, //ISO 语言代码 (en-US,nl-NL)
文本:字符串
]}
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
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 product1.jpg, product2.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
property | type | description | default |
---|---|---|---|
mainImageId | string | ID of the image which is the base for all the frames. You can also use mainImageUrl | jsv-image |
mainHolderId | string | ID of the div where the presentation runs in. | jsv-holder |
mainImageUrl | string | URl of the first image, doesn't have to be in the document. mainImageId is not necessary with this option | |
totalFrames | number | Amount of frames in the presentation, more images means smoother rotations. | 72 |
imageUrls | string[] | Array of image urls, overrides totalFrames and imageUrlFormat | [] |
firstImageNumber | number | After loading the presentation this is the first frame visible. | 1 |
reverse | boolean | Invert the rotation direction when dragging. | false |
speed | number | Speed of rotating. -199 to 100 | 80 |
inertia | number | Delay when stop dragging. | 20 |
defaultProgressBar | boolean | Disable the build in progress bar, use this when you have implemented your own loader or don't like this one. | true |
imageUrlFormat | string | Format for determining the filenames of the frames {filename}xx.{extension} is the default ipodx.jpg => ipod1.jpg ipodxx.jpg => ipod01.jpg https://other.cdn/images/ipodxx.jpg => https://other.cdn/images/ipod_01.jpg | {filename}_xx.{extension} |
startFrameNo | number | Use this setting in combination with imageUrlFormat startFrameNo: 4 => first file is ipod_04.jpg | 1 |
autoRotate | number | Use this setting for rotating the view at start. Rotation stops when user drags the model or another animation method is called. | 1 |
autoRotateSpeed | number | Speed of autorotation. -199 to 100 | 1 |
autoRotateReverse | boolean | Use this setting for changing the direction of the auto rotating. | 1 |
enableImageEvents | boolean | Use this setting for enabling click pinch and wheel events on images. | 0 |
zoom | boolean | Use this setting for enabling zoom functions. Zoom on wheel event or pinch. | 0 |
zoomWheelSpeed | number | Change the speed of zooming with the mousewheel. | 50 |
zoomMax | number | If zoom is enabled this is the max zoom factor. | 2 |
stopAtEdges | boolean | Blocks repeating images after reaching last image. | 0 |
autoCDNResizer | boolean | Set the query params height and width for use with an image resizer. | 0 |
enableChangeImageEvent | boolean | Enable changeImage event on rotation, could be CPU heavy | 0 |
cursorConfig | ICursorConfig | Change the cursors for the presentation | |
notificationConfig | InotificationConfig | Configure 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 - 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;
}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
]}