How to Make an Element Fade Out After Adding a Class in JQuery

I'm struggling with fading out an image after applying a tilt class to it. The transition doesn't seem to work properly and the image just disappears without the expected animation.

The class I'm trying to add simply tilts the image 90 degrees.

You can see the issue in action on my jsfiddle:http://jsfiddle.net/sqHxq/4/

Here is the code snippet:

HTML

<div id="logo" style="z-index:10">
<img src="http://s17.postimg.org/lb2un1g0r/image.png" alt ="">
</div>
<div id="other" style="z-index:0">
<img src="http://cdn1.iconfinder.com/data/icons/humano2/32x32/actions/old-edit-redo.png" alt="">
</div>

CSS

.tilt {
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}

#logo {
cursor: pointer;
max-width: 241px;
position:absolute;
top:0;
left:0;
}

#other {
cursor: pointer;
max-width: 241px;
position:absolute;
top:0;
left:0;
}

Javascript

$(document).ready(function () {
$('#logo').hide().delay(250).fadeIn(1000);
$('#other').hide().delay(750).fadeIn(1000);

$("#logo").click(function() {
        $('#logo').addClass("tilt").fadeOut(2000);
});
});

Answer №1

To achieve the desired effect, it seems like the fading animation should be applied to the image element rather than the entire div. Currently, the div fades in and then immediately hides; therefore, you should apply the fade effect to the image itself.

$(document).ready(function () {
    $('#picture').hide().delay(300).fadeIn(1200);
    $('#details').hide().delay(800).fadeIn(1200);

    $("#picture").click(function() {
            $('#picture').addClass("zoom");
            $('#picture').find('img').fadeOut(1500);
    });
});

Answer №2

My approach was to enhance the CSS transition by incorporating opacity. Check out the results here: http://jsfiddle.net/yNwZg/5/. I had to use important for it to work, although I acknowledge that's not ideal. I believe with some adjustments, you could achieve even better results than what I did.

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

What is the process for eliminating an attribute using adblock?

Is it possible to eliminate specific attributes with an ad blocker on a webpage? I am specifically interested in removing the title attribute, as shown in this example: <p title="Free Web tutorials">W3Schools.com</p> After applying the ad blo ...

Utilizing the `repeat` function within `grid-template-areas` eliminates the need to manually repeat grid cell

When working with grid-template-areas in CSS grid, I encountered a situation where I wanted a header to span the entire width. Instead of defining the template-grid-columns with repeat(12, 1fr), I was searching for a way to utilize repeat() so that I would ...

What are some ways to avoid sorting parameters in AngularJS when making a GET request using $resource?

My resource is: angular.module('myApp.services') .factory('MyResource', ['$resource', function ($resource) { return $resource('http://example.org', {}, {}); }]); How I send a GET request: MyResourc ...

I'm feeling overwhelmed by trying to send data from Jquery to php and then successfully retrieving the data

Here's the HTML snippet I'm working with: <form action="http://localhost/xiuno" method="post"> <h1>TEST</h1><br/> <input type="submit" value="submit" id="submit"/> </form> <script type="text/javasc ...

Refresh the page with cleared cache using window.location.reload

Is there a way to reload a page using JavaScript and still clear the cache, ensuring that the refreshed page shows the latest content from the server? It seems that other browsers are not displaying the most up-to-date versions of the content. Anyone have ...

Developing a Navigation Bar Menu using JSON data and the power of Lodash

Seeking advice to enhance my code for creating a navbar menu from JSON data. Any suggestions on how to avoid calling getItems multiple times? Appreciate any feedback, thank you! var _ = require('lodash'); let menuConfig = [ { ID: 1 ...

Tips for extracting a specific attribute from an array of objects using both react and JavaScript while considering various conditions

I have a set of objects structured like this: const obj_arr = [ { id: '1', jobs: [ { completed: false, id: '11', run: { id: '6&apos ...

What could be causing my jQuery script to not be able to identify elements with changing IDs?

I have this code snippet that is supposed to apply a class attribute to the span element with id "saved" based on the correct match, but for some reason it's not working as expected. I've gone over it multiple times, but can't seem to pinpoi ...

The HTML iframe is displaying blank content

I'm trying to embed a webpage within another webpage using an iframe. I attempted to do so with this simple code: <iframe src="http://edition.cnn.com/" id="i_frame"></iframe> JSFIDDLE However, nothing is displaying. Any thoughts on why ...

When the response is manually terminated, the next middleware layer in express.js is invoked

I recently noticed an unusual occurrence: Even though I am explicitly ending the request using res.json() in one express middleware, the request still cascades down to the next middleware. It is important to mention that I am not utilizing next() anywhere ...

Why isn't my jquery textchange event firing properly?

I have a textbox named txtEmpcode. I want to display an alert message when it loses focus. I've tried writing jQuery for this functionality, but unfortunately, it's not working... Here is the jQuery code: $(document).ready(function(){ var p ...

Chart.js outdated data not being cleared

This query has been repeated numerous times, and despite my efforts to find a solution in previous discussions, I have not been successful. As part of the reporting feature, I am creating multiple bar charts using a for loop. I am utilizing node.js with ...

Tracking user session duration on a React Native app can be achieved by implementing a feature that monitors and

I'm currently focusing on tracking the amount of time a user spends on the app in minutes and hours, and displaying this information. I have successfully implemented the functionality to count minutes, but I am struggling to figure out how to track wh ...

The implementation of a custom event for jQuery rows is not functioning as expected

I need assistance with jQuery code to add click events only to columns in a row that have text in the first column. Specifically, I want to hide rows containing "1/" in the first column when clicked on for the first row. <table class="results"> < ...

Laravel fails to display image on the webpage

Looking at my view.blade.php, I have the following: {{HTML::image('resources/views/Folder/Subfolder/Subfolder/Photo/'.$item->Photo)}} The value of $item->Photo is taken from the database to display the image. Within the same view, I also ...

Ways to access the content of the chosen <td> element using Vue?

I have a dynamic table where I retrieve data using $.ajax() from a database. The content in the rows is editable, and I need to save the changes made with vue.js. After updating the content, an $.ajax() function with 4 parameters (name, client_id, url, and ...

How can I make a clickable <div> easily navigable with tab functionality?

I am currently tackling a project that involves implementing an onclick event within a <div>. While I've successfully set up the primary functionality, there is one issue at hand. Specifically, I need the onclick event to trigger when a user nav ...

Navigating the authorization header of an API request in a Node environment

const authHeader = req.headers["authorization"]; I have a question that may come across as basic - why do we use ["authorization"] instead of just .authorization? After some research, I discovered it had to do with case sensitivity but ...

The setState function in React updates the value, however, when a form is submitted, it captures and

Encountering a problem with a modified field value not remaining on the form after submission. Working on a form where users can upload images. The image URL returned by the hosting service is saved in a state variable using this.setState({ im ...

What could be causing my jQuery to not retrieve the value of the <select> element?

Here's a snippet from my index.html file: <body> <select id="car"> <option value="TOYOTA">TOYOTA</option> <option value="BMW">BMW</option> </select> <input type=button id="get_btn" valu ...