Altering the state of a transformation when hovering

Here is an example of some CSS code I am working with:

    .some_class{
        width: 30%;
        height: 120px;
        margin-left: 10%;
        margin-right: 10%;
        margin-top: 100px;
        float: left;
        @include boxShadowLevel(2);
        transition: box-shadow 0.4s, transform 0.4s;

        transform: scale(0);

        &:nth-child(odd):hover{
            transform: translate(-3px, -3px) scale(1.1);
            @include boxShadowLevel(3);
        }

        &:nth-child(even):hover{
            transform: translate(3px, -3px) scale(1.1);
            @include boxShadowLevel(3);
        }

        // Additional CSS code here (not relevant for the question)

    }

In this code snippet, you can see that the default transform style is set to scale(0), and it gets faded in using some JavaScript code during the page load.

$(elem[i]).css("transform", "scale(1)")

The issue I'm encountering is that the hover effect does not seem to work, possibly due to the initial transform setting.

Is there a way to resolve this problem without needing to add another wrapper div or any other workaround?

Answer №1

After some exploration, I successfully arrived at the resolution by myself. Below is the snippet of my SCSS code with the additional "show" class:

.some_other_class{
    width: 40%;
    height: 150px;
    margin-left: 5%;
    margin-right: 5%;
    margin-top: 80px;
    float: right;
    @include boxShadowLevel(2);
    transition: box-shadow 0.3s, transform 0.3s;

    transform: scale(0);

    &.show{
        transform: scale(1);
    }

    &:nth-child(odd):hover{
        transform: translate(-4px, -4px) scale(1.1);
        @include boxShadowLevel(3);
    }

    &:nth-child(even):hover{
        transform: translate(4px, -4px) scale(1.1);
        @include boxShadowLevel(3);
    }

    // Additional CSS properties go here (irrelevant to the specific inquiry)

}

I then incorporated the "show" class instead of manually adjusting the transform in JavaScript:

$(elem[i]).addClass("show")

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

Hide fields that are not being sent to the controller

I've set up a lightbox with several input elements using HTML helpers for a create action. These fields are optional, but I've applied the digit rule to them in jQuery validation. Users can open the lightbox and fill out these optional fields if ...

What is the best method for updating inner html with AJAX using the results obtained from json_encode?

If you need further clarification on how this works, feel free to check out this fiddle for a demonstration. In my setup, I have multiple DIVs each with a unique ID such as desk_85 (the number changes accordingly). <div class="desk_box_ver id="desk_8 ...

Having trouble changing the icon in Google Maps during the event?

Seeking guidance with Google API V3 as a newcomer. The task at hand is to switch the icon during a zoom event. Everything works smoothly except for the part where I need to detect the change in zoom and modify the icon from a basic circle to Google's ...

Choosing the type attribute of an input tag by using a javascript variable as a condition: What's the best approach?

I am currently utilizing an input tag on the client side to receive text input. <input type="text" class="form-control" placeholder="Enter Message" id="messageText" autofocus/> My goal now is to dynamically set the type attribute based on a Javasc ...

You won't be able to view over 15 KML layers on a page that relies on Google Maps API

I've encountered an unusual issue: I need to create multiple KML layers from separate KML files and display them on a single map window. The number of files ranges from just a couple to less than fifty. Currently, my code works perfectly when given 1, ...

Updating the language of jQuery Datatables Buttons

I am currently utilizing the impressive jQuery Datatables plugin on my MVC razor website. While the internationalization feature works flawlessly, it does not cover the text for buttons. Here is the script I am using: $(document).ready(function () { $ ...

Encountering an Uncaught SyntaxError when using json.parse on a Django queryset that has been serialized to JSON

Encountering the error Uncaught SyntaxError: Unexpected Token while attempting to parse the JSON data. Here is my AJAX code (json2.js): $.ajax({ type: 'POST', url: '/best_choose/invoice/item_search.json/&apos ...

Tapping on an HTML element that is populated from PHP using jQuery AJAX may fail to function

I am facing an issue with a page where clicking a button should display a table with an "id" attribute that is loaded through jQuery AJAX with PHP. Strangely, the click event on table cells is not working in my JavaScript. Can someone please take a look at ...

Looking for a way to make one image disappear briefly while transitioning to another image in Javascript

**Hey there, coding enthusiasts! I could really use some help right now. I am trying to create a smooth image transition effect using Javascript, where one image fades out while the next one fades in seamlessly. As someone who is still relatively new to pr ...

Tips for preventing DIV elements from overlapping

In the process of creating a CSS design for a SIM game I enjoy playing, a client requested four boxes: two large ones with two smaller ones aligned horizontally in between. Everything was going smoothly until I attempted to add headers to the boxes. The en ...

How is it possible for me to retrieve data values directly from a sequelize model?

My question is straightforward - when doing a single select in sequelize, a model is returned. Inspecting this model reveals various options such as dataValues, _prevValues, _change, _options, isNewRecord, and more. What puzzles me is that you can also a ...

Extend the height of bootstrap 5.2.0 row/column to reach the bottom of the page

I'm having difficulty extending the left navigation section to reach the bottom of the page while remaining responsive. Despite trying various solutions like h-100, flex-grow, min-vh-100m self-align: stretch, nothing seems to solve the issue. Check o ...

What are some strategies to prevent a fixed sidebar from obscuring content while zooming in?

I've been working on adding a fixed sidebar for a table of contents (TOC) to a website, where the sidebar stays in place as the user scrolls up and down. My implementation includes the following HTML code: https://i.sstatic.net/jAY8l.png and CSS co ...

Tips for managing pagination in a Single Page Application

Within my Single Page Application (built with Javascript and AngularJs), I have an items list that is paginated, displaying 10 items per page. To ensure that the user's current pagination remains intact even when navigating to other pages, I store th ...

Displaying JSON data from the API on a webpage within a NodeJS weather application

Currently, I am in the process of developing a weather application using NodeJS. I have successfully retrieved JSON formatted data from the weather site's API. Nonetheless, I am perplexed about how to transmit this data to the application. Below is a ...

Passing variables through a promise chain and utilizing the finally method

My current endeavor involves constructing a log for an Express API, yet I am encountering difficulties in extracting the data for logging. I have successfully logged the initial req and res objects within the finally block, but I am uncertain about how to ...

"Easily toggle the visibility of values in checkboxes and organize them into groups with the power of JavaScript

Hey there! I am currently working on a project that involves grouping checkboxes and hiding/unhiding their content based on user interaction. Essentially, when the page first loads, the "All CARS" checkbox will be checked by default. If I then check the "C ...

Unable to be translated using Google Translate

Attempting to use Google translate API with AJAX and Javascript: $.ajax({ type : "GET", url : "https://www.googleapis.com/language/translate/v2", dataType : 'jsonp', cache : false, contentType : "applicat ...

How can I best divide this string in the most straightforward way?

Additional texts include: identifier_100D_200A identifier_400D_500A I am looking to extract just the values: 100D_200A 400D_500A What's the easiest way to remove "identifier_" from the strings and save them in a new variable? ...

Retrieve a specific key value from a dictionary within a Flask function by employing JavaScript

I'm currently working on a feature where a user can input something in a search field, and upon submitting, the script should send a request to a Flask function using JavaScript. The response data should then be loaded accordingly. However, I've ...