pchen66 / panolens.js

Javascript panorama viewer based on Three.js
https://pchen66.github.io/Panolens/
MIT License
2.79k stars 498 forks source link

HoverElement on click. #394

Open CasperWind opened 2 years ago

CasperWind commented 2 years ago
Description

im not so good in javascript. so i hope you can help. Is there a way to make the HoverElement to trigger onClick and not onHover?

Panolens version
Browser
OS
JoseManuelFV commented 1 year ago

However, in the next few days it is possible that a pull request will be created. Current listeners can be overwritten

Ideally, the infospot class should be refactored so that the hoverenter doesn't control the element

overrideInfospotEvents(infospot){

  infospot._listeners.hoverenter = [];
  infospot._listeners.click = [];

  infospot._listeners.hoverenter.push((ev)=>{
    if ( !infospot.container ) { return; }

    const cursorStyle = infospot.cursorStyle || ( infospot.mode === 1 ? 'pointer' : 'default' );
    const { scaleDownAnimation, scaleUpAnimation } = infospot;

    infospot.isHovering = true;
    infospot.container.style.cursor = cursorStyle;

    if( infospot.animated ){
      scaleDownAnimation.stop();
      scaleUpAnimation.start();
    }

  });
  infospot._listeners.click.push((ev)=>{
    if ( !infospot.container ) { return; }

    if(ev.mouseEvent.which != 1) { return; }

    const { element } = infospot;

    if( infospot.element && ev.mouseEvent.clientX >= 0 && ev.mouseEvent.clientY >= 0 ){
      const { left, right, style } = element;
      if ( element.mode === 2 || element.mode === 3 ) {

          style.display = 'none';
          left.style.display = 'block';
          right.style.display = 'block';

          // Store element width for reference
          element._width = left.clientWidth;
          element._height = left.clientHeight;

      } else {

          style.display = 'flex';
          if ( left ) { left.style.display = 'none'; }
          if ( right ) { right.style.display = 'none'; }

          // Store element width for reference
          element._width = element.clientWidth;
          element._height = element.clientHeight;

      }
    }
    infospot.lockHoverElement();
  });
}