Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom on hover #31

Closed
timrombergjakobsson opened this issue Apr 4, 2017 · 7 comments
Closed

Zoom on hover #31

timrombergjakobsson opened this issue Apr 4, 2017 · 7 comments
Labels

Comments

@timrombergjakobsson
Copy link

Hi, is there any possibility to zoom in on high res image on hover? I've only found on click. Thanks!

@kingdido999
Copy link
Owner

No, I think zoom on hover would cause poor user experience and inconsistent behavior between desktop and touch device.

@kingdido999
Copy link
Owner

kingdido999 commented Apr 4, 2017

@timrombergjakobsson However, you can achieve this by simply adding an event listener to your images, then use API to open up the image. Something like this:

const zooming = new Zooming()

// listen() takes either a single Element or, in this case, a CSS selector
zooming.listen('.zoomable')

const zoomable = document.getElementsByClassName('zoomable')

for (let i = 0; i < zoomable.length; i++) {
  const img = zoomable[i]
  img.addEventListener('mouseenter', function onMouseEnter (event) {
    zooming.open(event.target)
  })
  
  img.addEventListener('mouseleave', function onMouseLeave (event) {
    zooming.close()
  })
}

JSFiddle

@timrombergjakobsson
Copy link
Author

Ok, thanks!

@timrombergjakobsson
Copy link
Author

Hm weird, I tried your example I only get Uncaught TypeError: zooming.listen is not a function? I tried console loging the instance of Zooming and its there but the function listen does not seem to exist?

@kingdido999
Copy link
Owner

kingdido999 commented Apr 5, 2017

@timrombergjakobsson Here is a working example. I updated the previous comment as well.

@timrombergjakobsson
Copy link
Author

@kingdido999 Thanks a lot!

@veebull
Copy link

veebull commented Jun 6, 2017

About example
When photo was zoomed via hover event if you begin to grab and your mouse is outside of image, photo is zooming out and it doesn't work anymore. It works only after reload a page.
How to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants