vue2,实现圆角梯形的tab+阴影效果

效果图


代码

<template>
  <div class="main">
    <div class="content">
      <div class="nav1" ref="nav1" @click="cutTab('nav1','a')">aaaa <span ref="a" class="a"></span></div>
      <div class="nav2" ref="nav2" @click="cutTab('nav2','b')">bbbb <span ref="b" class="b"></span></div>
      <div class="nav3" ref="nav3" @click="cutTab('nav3','c')">cccc <span ref="c" class="c"></span></div>
    </div>
    <div class="list">
    </div>
  </div>

</template>
<script>

export default {
  components: {},
  data() {
    return {
    }
  },
  computed: {},
  watch: {},
  methods: {
    cutTab(select, type) {
      // 三个nav是控制层级
      const arr = ['nav1', 'nav2', 'nav3',]
      const valueToRemove = select;
      // 得到一个新的数组,不包含选择的nav,设置未选择的样式
      const newArr = arr.filter(item => item !== valueToRemove);
      newArr.forEach(it => {
        this.$refs[it].style.backgroundColor = '#f8f8f8';
        this.$refs[it].style.color = '#7e7e7e';
        this.$refs[it].style.zIndex = '1';
      })
      // 设置选择的样式
      this.$refs[select].style.backgroundColor = '#ffffff';
      this.$refs[select].style.color = '#000';
      this.$refs[select].style.zIndex = '99';
      if (select == 'nav1') {
        this.$refs.nav2.style.zIndex = '2';
      }
      // 三个span是画梯形的+阴影的
      const arr1 = ['a', 'b', 'c',]
      const valueToRemove1 = type;
      const newArr1 = arr1.filter(item => item !== valueToRemove1);
      newArr1.forEach(it => {
        this.$refs[it].style.backgroundColor = '#f8f8f8';
      })
      this.$refs[type].style.backgroundColor = '#ffffff';
    }

  },
  created() {
  },
  mounted() {
  },
}
</script>
<style>
.main {
  box-shadow: 0px 0px 8px #ededed;
  width: 300px;
  margin: 80px;
}
.content {
  width: 300px;
  overflow: hidden;
  padding: 10px 0px 0px;
  display: flex;
  align-items: baseline;
}

.nav3,
.nav2,
.nav1 {
  position: relative;
  text-decoration: none;
  display: inline-block;
  width: 100px;
  font-size: 12px;
  color: #7e7e7e;
  line-height: 24px;
  text-align: center;
  height: 24px;
  font-weight: 600;
  z-index: -1;
}
.nav1 {
  z-index: 2;
}
.nav2 {
  z-index: 1;
}
.a {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 1px solid #ededed;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  box-shadow: 3px -3px 5px #ededed;
  transform: perspective(10px) scale(1.1, 1.3) rotateX(5deg);
  z-index: -1;
  background: #fff;
}
.b {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;

  border: 1px solid #ededed;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  box-shadow: 0px -3px 5px #ededed;
  transform: perspective(10px) scale(1.1, 1.3) rotateX(5deg);
  z-index: -1;
  background: #f8f8f8;
}
.c {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;

  border: 1px solid #ededed;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  box-shadow: 3px -3px 5px #ededed;
  transform: perspective(10px) scale(1.1, 1.3) rotateX(5deg);
  z-index: -1;
  background: #f8f8f8;
}

.list {
  width: 300px;
  height: 300px;
  background-color: #776d6d;
}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue 2可以结合Lemon-IMUI和WebSocket来实现聊天功能。下面是一个简单的示例代码,演示了如何在Vue 2中使用Lemon-IMUI和WebSocket实现聊功能: 1. 首先,安装LemonIMUI和Vue-Socket.io: ``` npm install lemon-imui vue-socket.io ``` 2. 在Vue组件中引入Lemon-IMUI和Vue-Socket.io: ```javascript import LemonIMUI from 'lemon-imui'; import VueSocketIO from 'vue-socket.io'; Vue.use(LemonIMUI); Vue.use(new VueSocketIO({ debug: true, connection: 'http://your-websocket-server-url', })); ``` 3. 创建一个聊天界面的Vue组件,并在模板中使用Lemon-IMUI的组件: ```vue <template> <div> <lemon-chat :messages="messages" /> <lemon-input @send="sendMessage" /> </div> </template> <script> export default { data() { return { messages: [], // 聊天消息数组 }; }, methods: { sendMessage(message) { this.$socket.emit('chat', message); // 发送消息到WebSocket服务器 }, }, mounted() { this.$socket.on('chat', (message) => { this.messages.push(message); // 接收到WebSocket服务器发送的消息 }); }, }; </script> ``` 4. 在你的WebSocket服务器上实现消息的接收和转发逻辑,将接收到的消息广播给所有连接的客户端: ```javascript const io = require('socket.io')(server); io.on('connection', (socket) => { socket.on('chat', (message) => { io.emit('chat', message); // 广播消息给所有连接的客户端 }); }); ``` 这样,你就可以使用Vue 2、Lemon-IMUI和WebSocket实现聊天功能了。注意替换示例代码中的WebSocket服务器URL为你自己的服务器URL。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值