hover-effect icon indicating copy to clipboard operation
hover-effect copied to clipboard

Canvas image is squished, can i make the canvas image size to cover

Open gabe72 opened this issue 5 years ago • 4 comments

image

Images even if i make the exact same size, as the canvas it ends up zooming the image and in some images makes it squished how to get the image to behave like the css property background-size: cover

gabe72 avatar May 03 '20 08:05 gabe72

Hey,

I published an update a while ago with the background: cover behaviour. Can you share a demo / some code, with your problem so I can help you?

robin-dela avatar May 04 '20 00:05 robin-dela

Hi, thanks for the reply, I updated the files with the new ones still the same issue.

enclosing part of code below, Html with dummy links

`

        <a href="" target="_blank">
            <section class="project-holder">
                <div class="project">
                    <div class="project-img" data-tilt data-tilt-max="8" data-tilt-perspective="500" >
                        <div class="projectImage" data-displacement="http://localhost/gabe/wp-content/uploads/2020/04/14.jpg" data-intensity="-0.4"  data-easing="Sine.easeOut">
                            <img src="https://images.unsplash.com/photo-1587614382231-d1590f0039e7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80" alt="">
                            <img src="https://images.unsplash.com/photo-1519771773581-4ec4145d8a61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=872&q=80" alt="">
                        </div>
                        <div class="overlay"></div>
                    </div>
                    <div class="project-details">
                        <h3 class="split"></h3>
                        <p class="type"></p>  
                    </div>    
                </div>
            </section>  
        </a>    
`

JS

`function displacement(){ Array.from(document.querySelectorAll('.projectImage')).forEach((el) => { console.log(el); const imgs = Array.from(el.querySelectorAll('img')); new hoverEffect({ parent: el, intensity: el.dataset.intensity || undefined, speedIn: 1, speedOut: 0.5, easing: el.dataset.easing || undefined, hover: el.dataset.hover || undefined, image1: imgs[0].getAttribute('src'), image2: imgs[1].getAttribute('src'), displacementImage: el.dataset.displacement });

}); };`

gabe72 avatar May 04 '20 02:05 gabe72

Hi, thanks for the reply, I updated the files with the new ones still the same issue.

enclosing part of code below, Html with dummy links

`

        <a href="" target="_blank">
            <section class="project-holder">
                <div class="project">
                    <div class="project-img" data-tilt data-tilt-max="8" data-tilt-perspective="500" >
                        <div class="projectImage" data-displacement="http://localhost/gabe/wp-content/uploads/2020/04/14.jpg" data-intensity="-0.4"  data-easing="Sine.easeOut">
                            <img src="https://images.unsplash.com/photo-1587614382231-d1590f0039e7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80" alt="">
                            <img src="https://images.unsplash.com/photo-1519771773581-4ec4145d8a61?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=872&q=80" alt="">
                        </div>
                        <div class="overlay"></div>
                    </div>
                    <div class="project-details">
                        <h3 class="split"></h3>
                        <p class="type"></p>  
                    </div>    
                </div>
            </section>  
        </a>    

` JS

`function displacement(){ Array.from(document.querySelectorAll('.projectImage')).forEach((el) => { console.log(el); const imgs = Array.from(el.querySelectorAll('img')); new hoverEffect({ parent: el, intensity: el.dataset.intensity || undefined, speedIn: 1, speedOut: 0.5, easing: el.dataset.easing || undefined, hover: el.dataset.hover || undefined, image1: imgs[0].getAttribute('src'), image2: imgs[1].getAttribute('src'), displacementImage: el.dataset.displacement });

}); };`

You can try the 'imagesRatio' property to get the background size cover effect

new hoverEffect({
       ...
        imagesRatio: 9 / 16,   // *** height : width ratio of your images
       ....
});

Remember it is not same as css aspect ratio as like width / height, it is reversed which took me a while to figure it out, although it is mentioned clearly in his documentation

snowiewdev avatar Jun 25 '22 00:06 snowiewdev

@robin-dela how do i make the image automatically cover/fill the whole parent element without tweaking it all the time?

and i have two pictures that have different sizes.

edgar-505 avatar Feb 25 '23 22:02 edgar-505