Transition CSS to change an image from black and white to color

Several websites feature a transition from black and white to color when hovering over an image using the :hover selector. I am interested in achieving this effect without any user interaction. Specifically, I want the image to start as black and white and gradually fade to its colored version after 10 seconds.

Can CSS be used to accomplish this?

Answer №1

Is this the desired effect?

@keyframes toColor {
    0%    { -webkit-filter: grayscale(100%); filter: grayscale(100%); }
    25%   { -webkit-filter: grayscale(75%); filter: grayscale(75%); }
    50%   { -webkit-filter: grayscale(50%); filter: grayscale(50%); }
    75%   { -webkit-filter: grayscale(25%); filter: grayscale(25%); }
    100%  { -webkit-filter: grayscale(0%); filter: grayscale(0%); }
}


img.desaturate { 
   animation: toColor 10s;
}
<img src="http://i.imgur.com/gMPdDHk.jpg" alt="Lena Söderberg" style="width: 300px;" class="desaturate">

Answer №2

An alternative method to implement rollOver functionality for triggering the image colorization effect when hovering over an image.

img{ filter: grayscale(100%); transition: filter .3s ease-in-out;}
img:hover { filter: none;}

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

Send only the modified form fields when making an AJAX PUT request to the REST API

I need to update my data using an AJAX request triggered by clicking the Save button on a form with multiple fields. Currently, the update only works when all fields are filled out because I'm passing $('#field').val(). But what if I only wa ...

Adjust the width of the container and rotate the text accordingly

I am looking to display text vertically (like a y-axis chart label) and need the ability to rotate text of varying lengths while keeping it on one line. My attempt to achieve this using CSS3 transforms can be seen in this JSFiddle: .rotate { transform ...

Interactive pop-up window featuring conversational chat boxes

Trying to create a comment box within a Modal dialog box that is half of the width. The comments in this box should be read-only and created using div tags. Attempted reducing the width and using col-xs-6, but ending up with columns spanning the entire w ...

Utilizing Jquery to Load JSON Arrays as Tooltip Messages

I have successfully loaded the descriptions of my JSON variable into my script as tooltips. However, I am encountering two issues: When hovering over one sentence in my table, tooltips for all four sentences appear. It seems like I am unable to revert my ...

Load an external page, automatically update the URL in the browser, and ensure that the page remains in place even if

I am in the process of creating a website demo using Bootstrap 3 to ensure compatibility with IE7/8. The fixed navigation features 4 menu anchors that lead to landing pages for different subjects, each with dropdown menus containing a varying number of sub ...

How can I eliminate the whitespace and fix the positioning of div elements on the

There seems to be an issue with excessive white space between the nested divs .boxwrap and .lsmlbox + .rsmlbox, making it difficult to align .smlbox + .rsmlbox with .box. Is this problem more complex than anticipated? I am hoping to adjust the "inner" (ce ...

Steps to implement an image zoom function triggered by a button click

I'm working on a school project that requires me to use only html, css, and javascript for creating a website. Currently, I'm designing a landing page with a button that will navigate the user to another page. My goal is to have the background im ...

Having trouble getting AngularJS ngCloak to function properly?

My post category page is supposed to display a message if there are no posts. However, the HTML appears briefly when the page loads and then hides. I thought using ngCloak would solve this issue, but it doesn't seem to be working for me. Here's t ...

Text spilling out of a floated division

I'm currently working on a fluid layout design, but I've encountered an issue with the left menu text overflowing. I can't seem to get overflow:hidden to work properly. You'll notice that in the blue area, I have highlighted the text t ...

Encountered a MultiValueDictKeyError in Django at /employeeUpdate/ after making changes to the data

Encountering a django error "MultiValueDictKeyError at /employeeUpdate/ 'id'" after making changes to the data. Here is the code snippet from my views.py: def employeeUpdate(request): id = request.POST['id'] emp_username = requ ...

Ways to eliminate the vertical scroll feature in a kendo chart

I am encountering an issue while loading a kendo chart inside grid-stack.js where I am unable to resize the height properly. Whenever I decrease the height, a vertical scroll appears which should not happen. I have tried setting the height to auto and refr ...

When printing, the footer information appears jumbled together

When creating a footer for printing, I am utilizing the following CSS: @media all { .page-break { display: none; } .footer {display: none; } } @media print { .page-break { display: block; page-break-before: always; } .footer {display: bl ...

Retrieve the text from a string resource in Android while preserving HTML tags

When working on my app, I encountered an issue with displaying a string in a text view while utilizing html markup. Here is how I attempted to retrieve the string: String mystring = getResources().getString(R.string.Terms_And_Conditions); Unfortunately, t ...

z-index in CSS causes links to conflict

I am currently working on a project that requires an image to be displayed prominently on the website along with some links positioned behind it. However, I'm facing an issue where I can't click on the links after implementing z-indexes to layer ...

Ways to determine if a textbox is empty and trigger a popup notification with jQuery

I'm having trouble with checking if the textbox is empty in my form. Every time I try to submit, instead of receiving an alert message saying "Firstname is empty," I get a message that says "Please fill out filled." ('#submit').click(func ...

Is there a way to retrieve the text content from a span element using JavaScript?

Revised for better organization and explanation of the question Hello, I am new to web programming so please bear with me. My question is about extracting customer information from the following code snippet: <span class="tag-element-content" ...

Arranging data points into one concise column

Important Note: The code above has been automatically generated by JavaServer Faces. I am working with the following code snippet: <span style="display: block;"> <input checked="checked" type="checkbox">ID <select size="1" &g ...

A single background image split into several div elements

I am facing an issue regarding the background image placement in multiple divs. When I set the position to fixed, the image repeats when I resize the screen. However, changing it to absolute causes each div to have its own image. Is there a solution to fi ...

Disabled radio buttons are appearing as if they have been chosen

While working on customizing the styles of radio buttons in a form, I encountered an issue where disabled radio buttons appeared selected even though they were supposed to show as disabled. Here is the code snippet that I used: input ::-ms-clear { ...

Having trouble locating the existing placeholder in my WordPress theme that I'm trying to change

I am currently using the KuteShop WordPress Woo-commerce template and I want to customize the Placeholder Text "I'm searching for..." and "All Cate." shown in the image below: Despite my efforts, I have been unable to locate where I can make these ch ...