Raas Masood
Raas Masood

Reputation: 1575

is it possible to animate a text inside a textbox

My UX guy come up with a requirement to animate a text inside a text-box. i have this animation css class, when applied to a text-box animates the text-box. Thats how it should be.

<input type="text" style="width:380px" class="login-wrongPassword" value="Animate This Text not the box">

i have created an example for reference

.login-wrongPassword {
  -webkit-animation-name: login-wobble-horizontal;
  animation-name: login-wobble-horizontal;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
  -webkit-animation-iteration-count: 1;
  animation-iteration-count: 1;
}

/* Wobble Horizontal */
@-webkit-keyframes login-wobble-horizontal {
  16.65% {
    -webkit-transform: translateX(8px);
    transform: translateX(8px);
  }
  33.3% {
    -webkit-transform: translateX(-6px);
    transform: translateX(-6px);
  }
  49.95% {
    -webkit-transform: translateX(4px);
    transform: translateX(4px);
  }
  66.6% {
    -webkit-transform: translateX(-2px);
    transform: translateX(-2px);
  }
  83.25% {
    -webkit-transform: translateX(1px);
    transform: translateX(1px);
  }
  100% {
    -webkit-transform: translateX(0);
    transform: translateX(0);
  }
}
<input type="text" style="width:380px" class="login-wrongPassword" value="Animate This Text not the box">

is is possible to animate only the text and not the text box itself. ??

Upvotes: 0

Views: 780

Answers (2)

amflare
amflare

Reputation: 4113

Yes. Use padding-left instead of transform

/* Wobble Horizontal */
@-webkit-keyframes login-wobble-horizontal {
  16.65% {
    padding-left: 10px;
  }
  33.3% {
    padding-left: 5px;
  }
  49.95% {
    padding-left: 8px;
  }
  66.6% {
    padding-left: 3px;
  }
  83.25% {
    padding-left: 5px;
  }
  100% {
    padding-left: 0;
  }
}

JSFiddle

As Santi mentions, you can fix the right side by using 'box-sizing: border-box'

Upvotes: 0

caramba
caramba

Reputation: 22490

Use CSS text-indent

.login-wrongPassword {
  -webkit-animation-name: login-wobble-horizontal;
  animation-name: login-wobble-horizontal;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-timing-function: ease-in-out;
  animation-timing-function: ease-in-out;
  -webkit-animation-iteration-count: 1;
  animation-iteration-count: 1;
}

/* Wobble Horizontal */
@-webkit-keyframes login-wobble-horizontal {
  16.65% {
    text-indent: 8px;
  }
  33.3% {
    text-indent: -6px;
  }
  49.95% {
    text-indent: 4px;
  }
  66.6% {
    text-indent: -2px;
  }
  83.25% {
    text-indent: 1px;
  }
  100% {
    text-indent: 0px;
  }
}
<input type="text" style="width:380px" class="login-wrongPassword" value="Animate This Text not the box">

Upvotes: 4

Related Questions