Fade In and / or Out Placeholder Text

大兔子大兔子 提交于 2019-12-11 09:05:52

问题


Is there a way to fade in and out an input's placeholder text?

I've tried:

$('.userBox::-webkit-input-placeholder').animate({color: '#888888'}, 500);

But this just crashes...


回答1:


If you want to fade out on focus, and fade back in on blur (when the input box is empty), the following should work in webkit:

HTML:

<input id="user_email" name="user[email]" placeholder="user@example.org" type="email" />

CSS:

input[type="email"]::-webkit-input-placeholder  {
  -webkit-transition: opacity 0.3s linear; 
  color: gray;
}

input[type="email"]:focus::-webkit-input-placeholder  {
  opacity: 0;
}

jsFiddle: http://jsfiddle.net/a9UA3/




回答2:


If you're referring to the placeholder text supplied by the browsers' implementation, I don't believe so. if you wanted to implement a custom placeholder using focus, blur & key* events then yes it's possible.




回答3:


Try using

$('.userBox::-webkit-input-placeholder').fadeOut(500);

Or, alternatively you could use this plugin.



来源:https://stackoverflow.com/questions/17625737/fade-in-and-or-out-placeholder-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!