Ways to incorporate zoom and flip effects into an image with the use of CSS and jQuery

I'm attempting to incorporate both flip and zoom effects into my project, but I've only been successful in achieving one effect.

The scenario is when the user clicks on the image, it zooms in. Now, I want to add a flip effect before the mouse leaves the image.

Could someone please assist me with implementing this using my existing code?

This is what I have tried so far:

HTML

<div class="flip">
    <div class='card'>
        <img src="http://cdn.ndtv.com/tech/images/doodle_for_google_2013.jpg" class="zoom_img" />
    </div>
</div>

CSS

.zoom_img {
    height: 250px;
    width: 250px;
    -webkit-transition: -webkit-transform 0.5s ease-in;
    -o-transition: -webkit-transform 0.5s ease-in;
}
.zoom_img_press {
    -moz-transform: scale(1.1);
    -webkit-transform: scale(1.1);
    -o-transform: scale(1.1);
}
.flip {
    -webkit-perspective: 800;
    width: 400px;
    height: 200px;
    position: relative;
    margin: 50px auto;
}
.flip .card .flipped {
    -webkit-transform: rotatex(-180deg);
}
.flip .card {
    width: 100%;
    height: 100%;
    -webkit-transform-style: preserve-3d;
    -webkit-transition: 0.5s;
}

Javascript

$(document).ready(function() {

    $('.flip').click(function(){
        $(this).find('.zoom_img').addClass('zoom_img_press').mouseleave(function(){
            $(this).removeClass('zoom_img_press');
        });
    });
    $(this).find('.zoom_img').addClass('flipped').mouseleave(function(){
        $(this).removeClass('flipped');
    });

});

Demo

Answer №1

Give this a try, I believe it will be beneficial for you.

Class featuring multiple transformations.

.zoom-flipper{
    -moz-transform: scale(1.8) rotatey(-90deg);
    -webkit-transform: scale(1.8) rotatey(-90deg);
    -o-transform: scale(1.8) rotatey(-90deg);
    transform: scale(1.8) rotatey(-90deg);    
}

Associated Script:

$('.flip').click(function(){
    $(this).find('.zoom_img').addClass('zoom-flipper').mouseleave(function(){
        $(this).removeClass('zoom-flipper');
    });
});

Check out the Demo

Answer №2

To enhance the styling of an image, first create two unique JavaScript functions. Next, utilize jQuery to manipulate the CSS properties of the image within these functions. Take a look at this example of jQuery code for CSS manipulation:

$(".className").css({"background-color":"black","font-size":"12px"});

You have the flexibility to adjust any CSS property within the curly brackets.

After defining the JavaScript functions, you can trigger them based on specific DOM events. For instance, the zoom function could be activated by the onClick event, while the flip function could be triggered by the onMouseOut event.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unexpected issue with the JSON.parse() function in a node.js environment

When working with TCP in node.js, I encountered an issue while trying to parse stringifyed JSON data. My code snippet below showcases how I attempted to achieve this. socket.on("data", function(data) { console.log(data.toString()); // Di ...

Unraveling exceptions in Node.js akin to handling them in Java

I'm seeking to develop a node application and I need guidance on exception handling. In Java, we utilize the exception class for this purpose. How can I achieve something similar in node? Are there any libraries available specifically for handling exc ...

Customizing Material-UI Grid: Is it possible to assign a background color solely to the cells, without affecting the surrounding empty spaces?

I've been experimenting with designing a grid system that incorporates a gradient background color. The issue I'm facing is that the background color extends to the empty spaces between the grid cells as well. Is there a way to scope the gradient ...

How can we effectively override the automatic contrasting color determination of buttons based on their background in Boostrap v5.2 SCSS compilation?

Buttons in Bootstrap v5.2 dynamically adjust the text color based on the button color. Currently, I am modifying the bootstrap variables override file to change the primary color for my custom theme $green: #369d6d !default; $primary: $green !default; Ho ...

Creating a Jest mock for Sendgrid in the __mocks__ directory

Here's my sendgrid code located in the __mocks__ directory: class MailService {} const mail = jest.fn( () => (MailService.prototype = { setApiKey: jest.fn(), send: jest.fn(), }) ); module.exports = mail; module.exports.MailS ...

asp.net menu control automatically hides items that exceed the width of the page

I'm currently using an asp.net menu control created from codebehind for a better user experience. However, when the browser is resized or the resolution is lower than intended, items that don't fit get pushed down to a second line. I want to hide ...

Assess transcluded content prior to template compilation in an AngularJS directive

I am currently developing a custom "collapseText" directive using AngularJS. The purpose of this directive is to display a specified maximum number of characters and provide a "Read More" option to expand the text if it exceeds the limit. My goal is for t ...

Ways to enlarge the parent container and reveal a concealed child element upon hovering without impacting neighboring containers

Currently, I am diligently working on the company service boxes and have a particular need... When hovering over: 1. The parent div should scale up and acquire box shadow without impacting the neighboring service boxes (it should appear to stand out above ...

Unexpected behavior by JavaScript function causing changes in unintended parts of the webpage

<div id="logo"><!-- logo --> <a href="index.php" id="ajax_link">My Site</a> </div><!-- end logo --> <?php if ($_SESSION['uid'] == "") { echo "<div id='main_menu' class='log&ap ...

Comparison of universal and descending selector in CSS

Can someone clarify when to use the universal selector versus the descendant selector in CSS? I've tried finding a clear explanation, but haven't come across one that explains the difference and when each should be used: div * .test{ color: re ...

Using Angular 4 to retrieve a dynamic array from Firebase

I have a dilemma while creating reviews for the products in my shop. I am facing an issue with the button and click event that is supposed to save the review on the database. Later, when I try to read those reviews and calculate the rating for the product, ...

Implementing a PHP script to prompt the user to input two random integers and sum them up on a webpage through $_POST method

My current project involves creating an interactive adding game using PHP and HTML. In this game, the user is required to guess the correct sum of two randomly generated integers. However, I am encountering an issue where each time the user submits their a ...

String constant without an ending

My Description has a single quote character('). How can I make sure it doesn't break the code? <a href='javascript:select("<%= pageBean.replace(list.getColumn(0), "'", "'") %>", "<%= pageBean.replace(list.getColumn(1), ...

What is the best way to relocate a function from Gruntfile.js?

Within my Gruntfile.js, I currently have a function called my_function: // Gruntfile.js module.exports = function(grunt) { var config = my_function(grunt); grunt.initConfig(config); }; function my_function(grunt) { //some code return c ...

What steps should be taken to effectively integrate Amplify Authenticator, Vue2, and Vite?

Embarked on a fresh Vue2 project with Vite as the build tool. My aim is to enforce user login through Cognito using Amplify. However, when I execute npm run dev, I encounter the following issue: VITE v3.1.3 ready in 405 ms ➜ Local: http://127.0.0 ...

Convert h264 video to GIF using Node.js

Currently, I'm utilizing the "pi-camera" library to successfully record video in a raw h264 format on my Raspberry Pi. However, I am encountering an issue with the node.js library "gifify" which keeps throwing the error "RangeError: Maximum call stack ...

centering pictures vertically on my webpage

Below is the code I am currently working with. It displays an image on the left and a description with a button on the right, side-by-side within the "promo_box_wrapper" container. However, I'm struggling to vertically align the image within its surro ...

Keep retrying a request until a valid response is received

I am working with an API that requests data from a backend service. Sometimes, the data may not be available at the time of the initial request. In such cases, I need the system to retry up to 5 times until the data is present. I can confirm that the dat ...

The issue of Google Maps API Marker Images not appearing in Internet Explorer

I am working with the Google Maps API Javascript V3 and encountering an issue specifically in Internet Explorer where my marker images are not displaying. Strangely, Adobe Browserlab shows that other browsers do not have this problem. The coordinates are ...

Working with AngularJS: Managing the values of two separate submit buttons

I'm trying to create a form with two submit buttons that will determine whether the form is saved as a draft or as a correct submission. One solution I am considering is adding a value/property to the submit buttons, perhaps using the ng-model attrib ...