Skip to content Skip to sidebar Skip to footer

Panzoom Library And Filling A Div With A Centered Image

The Panzoom library (https://timmywil.com/panzoom/demo/) allows you to move and zoom an image in a div: Everything is working properly. Now I would like these images to fill their

Solution 1:

I'm not sure, but I think this is ok:

var zoomWraper1 = document.querySelector(".zoom-wrapper1");
var zoomWraper2 = document.querySelector(".zoom-wrapper2");

var panzoom1 = Panzoom(document.querySelector(".zoom-area1"), {
  maxScale: 6
});
zoomWraper1.addEventListener("wheel", panzoom1.zoomWithWheel);

var panzoom2 = Panzoom(document.querySelector(".zoom-area2"), {
  maxScale: 6
});
zoomWraper2.addEventListener("wheel", panzoom2.zoomWithWheel);

panzoom1.pan(0, 0);
panzoom1.zoom(300 / document.querySelector(".zoom-area1 img").height);

panzoom2.pan(0, 0);
panzoom2.zoom(300 / document.querySelector(".zoom-area2 img").width);
body {
    width: 100%;
    height: 100vh;
}

button {
  margin-right: 20px;
}

.main-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.zoom-wrapper1 {
    width: 300px;
    height: 300px;
    border: 5px solid #1c6ea4;
  display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-wrapper2 {
    width: 300px;
    height: 300px;
    border: 5px solid #1c6ea4;
  display: flex;
    align-items: center;
    justify-content: center;
}
<htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1.0"><linkrel="stylesheet"href="style.css"><title>Document</title></head><body><divclass="main-container"><divclass="zoom-wrapper1"><divclass="zoom-area1"><imgsrc="https://images.unsplash.com/photo-1552288092-76e7d732366c?ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8cGFub3JhbWljfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&w=1000&q=80"></div></div><divclass="zoom-wrapper2"><divclass="zoom-area2"><imgsrc="https://i2.wp.com/digital-photography-school.com/wp-content/uploads/2013/08/1.-Moraine_final.jpg"></div></div></div><scriptsrc="https://timmywil.com/panzoom/demo/panzoom.js"></script><scriptsrc="script.js"></script></body></html>

Definitely the problem is that the zoom escapes to the sides, it is not directed to the point pointed by the mouse. This needs improvement.

Post a Comment for "Panzoom Library And Filling A Div With A Centered Image"