最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Animating text within the input field - Stack Overflow

programmeradmin2浏览0评论

I am developing a JavaScript console, in which when user types a mand and presses enter, the console does it.

One thing I was not able to figure out is how can one animate text in an input field. The input field will already have a value in itself, which I want to animate.

I can animate text with CSS animations for normal text, but that does not seem to work for input. Please check out this fiddle for the CSS text animation. If there were a way to animate text in input with CSS, it would be preferable.

Thus, could someone hint or suggest me any ways on how to achieve what I want?

Thanks a lot.

I am developing a JavaScript console, in which when user types a mand and presses enter, the console does it.

One thing I was not able to figure out is how can one animate text in an input field. The input field will already have a value in itself, which I want to animate.

I can animate text with CSS animations for normal text, but that does not seem to work for input. Please check out this fiddle for the CSS text animation. If there were a way to animate text in input with CSS, it would be preferable.

Thus, could someone hint or suggest me any ways on how to achieve what I want?

Thanks a lot.

Share Improve this question asked Jun 4, 2015 at 6:05 VeoVeo 2913 silver badges14 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

I have e up with a javascript logic which animates a particular text inside an input text field. Hope this answers your question.

var value = "Typing animation";
value.split("").forEach(function(elem, index){
  setTimeout(function(){
  $("input[type='text']").val($("input[type='text']").val()+elem);
}, index* 750); 
$("input[type=text]").focus();
}); 

Check following fiddle.

JSFiddle

You can try with an overlay over your input, and fill the actual text of the input after the animation finishes with some java script.

<div>
    <input type="text" value="Some text"></input>
    <span>Some text</span>
</div>

div{position:relative;}
span { 
    ...your h1 stuff here...
    position:absolute;
    left:2px;
}
input {font: bold 200% Consolas, Monaco, monospace;}

So I think you're probably looking for something like this?

https://jsfiddle/bv9onx6x/16/

That is going to listen for the onkeypress and then the JavaScript will fire and set the inner html of the new <h1> to whatever value is in the textbox.

发布评论

评论列表(0)

  1. 暂无评论