element plus 输入框样式模仿Material-UI

获取焦点状态
在这里插入图片描述

自定义指令

app.directive('focus', {  
  // 当被绑定的元素插入到 DOM 中时……  
  mounted(el) {  
    const descendants = el.querySelectorAll('.el-input__inner'); 
    var cssClass = 'newLable';
    el.classList.add(cssClass); 
    // 遍历并操作这些子孙节点  
    descendants.forEach((descendant) => { 
      // 这里可以根据需要进行任何操作,比如改变样式  
      // 或者添加事件监听器等  
      descendant.addEventListener('focus', () => {  
        console.log(el.childNodes[2]);
        el.childNodes[2].style.transform="scale(0.8)";
        el.childNodes[2].style.marginTop="-0.5rem";
        el.childNodes[2].style.background = '#fff'
        el.childNodes[2].style.color = '#1e90ff'
        el.childNodes[2].style.opacity="1";      
      });
      descendant.addEventListener('blur', () => {
        if(descendant.value==""){
          el.childNodes[2].style.color= '#c9bfbf';
          el.childNodes[2].style.transform="scale(1)";
          el.childNodes[2].style.marginTop="";
          el.childNodes[2].style.background = 'none'
          el.childNodes[2].style.opacity="0.8";
        }
      });  
    });  
  },  
  unmounted(el) {  
    // 移除事件监听器  
    const descendants = el.querySelectorAll('.el-input__inner'); 
    descendants.forEach((descendant) => {
      descendant.removeEventListener('focus', () => {});
      descendant.removeEventListener('blur', () => {});
     }); 
  },
  // 当指令所在的元素或其子元素更新时,更新函数将被调用  
  updated(el) {  
    // 根据需要执行更新操作  
  }  
}); 

全局样式

.el-form-item{
   position: relative !important;
}
.newLable /deep/.el-form-item__label{
   position:absolute ;
   z-index: 99;
   opacity:0.8;
    justify-content:flex-start;
    transition: all .2s ease-in-out ;
    color: #c9bfbf ;
    margin-left: 10px ;
     height: 1rem;
     align-items: center;
    margin-top: 0.5rem;
    -webkit-background-clip: content-box !important;
    background-clip: content-box !important;

}

.newLable /deep/ .el-input__inner::placeholder{
   opacity:0;
}

相关推荐

  1. input输入设置样式

    2024-04-03 14:12:03       33 阅读
  2. Element-UI 数字类型输入

    2024-04-03 14:12:03       64 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-03 14:12:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-03 14:12:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-03 14:12:03       82 阅读
  4. Python语言-面向对象

    2024-04-03 14:12:03       91 阅读

热门阅读

  1. python - 实现一个通用的插件类

    2024-04-03 14:12:03       37 阅读
  2. Matlab未装工具箱

    2024-04-03 14:12:03       45 阅读
  3. excel wps中编码格式转换

    2024-04-03 14:12:03       43 阅读
  4. Unity自定义框架开发

    2024-04-03 14:12:03       36 阅读
  5. 信创工程师招聘需求分析

    2024-04-03 14:12:03       42 阅读
  6. qgroundcontrol 遥控器校准-问题解决

    2024-04-03 14:12:03       28 阅读
  7. 了解黑客目的,防范黑客攻击

    2024-04-03 14:12:03       34 阅读
  8. rabbitmq调优--来自gpt

    2024-04-03 14:12:03       38 阅读