Here is a fiddle with a solution. This involves using a separate absolutely positioned div with transparency.
http://jsfiddle.net/jessekinsman/xywKm/3/
The HTML
<div class="container">
<div class="background">
</div>
<input type="text" name="test" class="white" />
</div>
The CSS
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
.container {
width: 200px;
height: 50px;
overflow: hidden;
position: relative;
}
.background {
position: absolute;
left: 100%;
background: red;
width: 100%;
height: 100%;
-webkit-transition: left 300ms linear;
transition: left 300ms linear;
opacity: 0.5;
-webkit-opacity: 0.5;
z-index:0;
}
.background.view {
left: 0;
}
.white {
background-color: white;
}
.red {
background-color: red;
}
input {
background-color: transparent none;
width: 100%;
height: 100%;
z-index: 100;
}
jQuery just to add and remove the classes
$("input").focus(function(e){
$(".background").addClass("view");
});
$("input").focusout(function(e){
$(".background").removeClass("view");
});
Probably the best option unless you have some specific styling on your input element that you don't want to loose. Then you should use a background image.
Here is a link to that fiddle
http://jsfiddle.net/jessekinsman/5aL4L/1/
Also wasn't sure if you wanted the animation to loop until some criteria is met. If that is the case, you should use the css transform option and have it loop until the criteria is met.
background-positionof abackground-image, but I don't see how you could animate a background color that way.