From b5c29352ed2adffe3b2f0fd52fe3a68db6b20c2d Mon Sep 17 00:00:00 2001 From: Ilya Pogorelov Date: Mon, 18 Dec 2023 21:04:56 +0200 Subject: [PATCH] Add option to hot spots --- doc/json-config-parameters.md | 5 +++++ src/js/pannellum.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/doc/json-config-parameters.md b/doc/json-config-parameters.md index 1e18927e..1ea7e5ac 100644 --- a/doc/json-config-parameters.md +++ b/doc/json-config-parameters.md @@ -358,6 +358,11 @@ changes in local image scale that occur due to distortions within the viewport. If set to a number, a fixed scaling is applied relative to the default hot spot size. Defaults to `false`. +#### `sticky` (boolean) + +When `true`, the hot spot will stick to the edges of the screen, always visible. +Defaults to `false`. + ### `hotSpotDebug` (boolean) When `true`, the mouse pointer's pitch and yaw are logged to the console when diff --git a/src/js/pannellum.js b/src/js/pannellum.js index 23af36db..355aba6c 100644 --- a/src/js/pannellum.js +++ b/src/js/pannellum.js @@ -2081,6 +2081,10 @@ function renderHotSpot(hs) { // Apply transform coord[0] += (canvasWidth - hs.div.offsetWidth) / 2; coord[1] += (canvasHeight - hs.div.offsetHeight) / 2; + if (hs.sticky) { + coord[0] = Math.min(canvasWidth - hs.div.offsetWidth, Math.max(0, coord[0])); + coord[1] = Math.min(canvasHeight - hs.div.offsetHeight, Math.max(0, coord[1])); + } var transform = 'translate(' + coord[0] + 'px, ' + coord[1] + 'px) translateZ(9999px) rotate(' + config.roll + 'deg)'; if (hs.scale) {