GithubHelp home page GithubHelp logo

gallery-with-zoom's Introduction

Gallery with zoom

Gallery with zoom using JavaScript, HTML and CSS only. No framework or libraries. This gallery is for desktop only.

This kind of gallery is very common nowdays. Give the user the abilaty to change and zoon the image without a single click. Just have to hover in the thumbnail to change the main image. Also can see a zoom of the image by hovering over the image.

Languages used

  • HTML
  • CSS
  • JavaScript

Explanation

The code is well divided, to make it easy to update and also to other people to understand. It has 5 functions. All with objective names.

The functions are:

  • handleChangeImageThumbnail: This function have the job to change the main image when hover over each thumbnails. Also change the style of the active thumbnail.

  • getMousePositionForLens: Here is where we calculate the x and y position of the cursor on the image. In addition, it set boundries to avoid the rectangular lens move out of the image.

  • handleZoomLensPosition: This function is responsible to set the position of both Lens and zoom container. To move the Lens, the function getMousePositionForLens is used to get the x, y values and set the left and top values of the Lens. To calculate the background Position and size of the zoom container, the fraction between the zoom container and the rectangular Lens is calculated. After this, the values are set.

  • handleZoomLensActivation: As the name suggest, here is where we acitivate the zoom and the Lens when the mouse in inside the image. Also where the background Image of the zoom_container is set.

  • handleZoomLensDeactivation: Deactivate the zoom and lens when cursor is out of the image.

The Event listeners:

There are event to the windom, the thumbnails and to the figure_image (the main image).

  • The event on the windom is the load event. To set the main image and the thumbnail style when load.
  • All thumbnails have an event to change the image and thumbnail style
  • The figure_image have 3 events. To show and hide rec_lens and zoom_container. Also to trigger the zoom logic.

How can I use it?

First, you can clone the project at your folder. Use the commande line on you folder:

git clone https://github.com/Vinicius-PR/Gallery-with-zoom.git

Then you will have all the code. Just open the index.html at your browser to see the result.

ScreenShot

Final Result

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.