Coder Social home page Coder Social logo

hover-zoom-module's Introduction

Hover-zoom module

Position-independent hover-zoom module

See demo here: https://www.cunninghamwebdd.com/demo/hover-zoom/

Summary

This is a simple hover-zoom module that you can place anywhere on a page. The aspect-ratio of the images are designed to be 1:1 since the containers are of 1:1 aspect-ratio.

The larger image should be 5 times larger than the smaller image. However any image will work, the magnification is done in the code.

The smaller image should have a height/width dimension of 300px by 300px.

The code uses a combination of requestAnimationFrame, variable caching, and translate3d to optimize performance.

Operation

This is designed around two-containers, the image that you want to magnify is on the left, and some text/description is on the right. When you hover on the small image, a larger-zoomed-in image will overlay the text/description container. When the mouse leaves the small-image area, the larger-zoomed-in image will disappear and the text/description will once again be visible.

Code implementation

There is a compressed file which includes a copy of jQuery, the actual code itself and the sample images.

Static implementation

This means that there will only be one image to be zoomed. In this case, all you'd need to do is to make sure your small image with a dimension of 300px by 300px be named small-image.jpg and the larger image to be shown for the zoom-effect to have a dimension of 1500px by 1500px (preferrably).

Include the hover-zoom-module.css, square-cursor.png, the hover-handler.js, files and the photos themselves.

Then drop the zoom-module part of the code in your site:

<div id="zoom-module">
  <div id="small-image-container">
    <img src="small-image.jpg" id="small-image" width="300px" height="300px">
  </div>
  <div id="text-container">
    <h1 class="big-text">Sample header</h1>
    <p>Sample text</p>
  </div>
  <div id="zoomed-image-container">
    <img src="large-image.jpg" id="large-image" width="1500px" height="1500px">
  </div>
</div>

Dynamic implementation

In the dynamic version, you'd have a script that changes the source of both the small and large images. Otherwise the rest is the same.

Note

This is only intended to be used on non-touch-screen devices eg. devices with a mouse, as the tracking does not work well on touch-based devices like phones.

This requires jQuery

hover-zoom-module's People

Contributors

jdc-cunningham avatar

Watchers

 avatar  avatar

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.