简体   繁体   English

输入框占位符/标签动画

[英]Input box placeholder/label animations

I have a input box with some text written in it like label or placeholder and on mouse hover I want to change that text and on click want to display a different text which act like a placeholder.我有一个输入框,其中写有一些文本,如 label 或占位符,在鼠标上 hover 我想更改该文本,然后单击要显示不同的文本,就像占位符一样。

I tried to write css but not able to achieve this,Is their need to write JavaScript to achieve this animation.我试过写css但是没能实现,难道他们需要写JavaScript来实现这个animation。

Instead Of Using input Field using HTML and CSS, You can easily use PrimeNG Float Label which is More Compactible而不是使用输入字段使用 HTML 和 CSS,您可以轻松使用 PrimeNG Float Label,它更紧凑

link: https://www.primefaces.org/primeng/floatlabel链接: https://www.primefaces.org/primeng/floatlabel

In Angular?在Angular? It's easy:这简单:

Component Code Behind组件代码隐藏

import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  placeHolder="";

  onMouseOver() {
    this.placeHolder = "Ein Text"
  }

  onMouseLeave() {
    this.placeHolder = "";
  }
}

And the HTML Part和 HTML 部分

<input type="text" (mouseover)="onMouseOver()" (mouseleave)="onMouseLeave()" [placeholder]="placeHolder">

If the mouse enter the input the placeholder will be visible.如果鼠标进入输入,占位符将可见。 Leave it is hidden.让它隐藏起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM