Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color with css over time back and forth

I was wondering if someone could help me change the color of a div from black to white after two seconds, then from white to black after two seconds, back again and so on as long as the div exists. Putting it other way, the div is only shown whenever a user clicks and drags a surface (just like the desktop selection area) and my objective is to change the color of the borders as described above while the user is still making his selection on the surface just as resizing the div.

like image 582
Joheo Avatar asked Sep 03 '13 00:09

Joheo


People also ask

What are 3 different types of color values you can use with CSS?

Each parameter (red, green, and blue) defines the intensity of the color and can be an integer between 0 and 255 or a percentage value (from 0% to 100%). For example, the rgb(0,0,255) value is rendered as blue, because the blue parameter is set to its highest value (255) and the others are set to 0.

How do I change colors in CCS?

Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.

How do I change the background color automatically in HTML?

You can set a background color for an HTML document by adding style="background-color:" to the <body> element.


1 Answers

If your browser requirements allow you to use css3 you don't need any javascript at all.

HTML:

<div class="blinkdiv">
</div>

CSS:

@-webkit-keyframes blackWhite {  
  0% { background-color: white; }
  50% { background-color: white; }
  51% { background-color: black; }
  100% { background-color: black; }
}

.blinkdiv {
    height: 100px;
    background-color: black;
    -webkit-animation-name: blackWhite;  
    -webkit-animation-iteration-count: infinite;  
    -webkit-animation-duration: 2s; 
}   

Here's an example: http://jsfiddle.net/tommcquarrie/w3Qy9/1/

like image 185
Tom McQuarrie Avatar answered Sep 17 '22 14:09

Tom McQuarrie