Angular - 响应式选项卡与下拉菜单
创始人
2024-10-15 01:00:32
0

下面是一个使用Angular实现响应式选项卡和下拉菜单的示例:

首先,在Angular项目中创建一个组件,比如TabDropdownComponent

tab-dropdown.component.html:

  • {{ tab.title }}
{{ tab.content }}

tab-dropdown.component.ts:

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

@Component({
  selector: 'app-tab-dropdown',
  templateUrl: './tab-dropdown.component.html',
  styleUrls: ['./tab-dropdown.component.css']
})
export class TabDropdownComponent {
  tabs = [
    { title: 'Tab 1', content: 'Content 1', active: true },
    { title: 'Tab 2', content: 'Content 2', active: false },
    { title: 'Tab 3', content: 'Content 3', active: false },
    { title: 'Tab 4', content: 'Content 4', active: false }
  ];
  selectedTab = this.tabs[0];
  showDropdown = false;

  selectTab(tab) {
    this.tabs.forEach(t => t.active = false);
    tab.active = true;
    this.selectedTab = tab;
  }

  toggleDropdown() {
    this.showDropdown = !this.showDropdown;
  }
}

tab-dropdown.component.css:

.tab-container {
  display: flex;
  flex-direction: column;
}

.tab-header {
  display: flex;
  justify-content: flex-start;
}

.tab-header li {
  cursor: pointer;
  padding: 10px;
  background-color: #eee;
}

.tab-header li.active {
  background-color: #ccc;
}

.tab-header .dropdown {
  position: relative;
}

.tab-header .dropdown ul {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1;
  display: none;
  background-color: #eee;
  padding: 10px;
  list-style: none;
}

.tab-header .dropdown ul li {
  cursor: pointer;
}

.tab-header .dropdown ul li:hover {
  background-color: #ccc;
}

.tab-header .dropdown ul li:first-child {
  margin-top: 10px;
}

.tab-header .dropdown ul li:last-child {
  margin-bottom: 10px;
}

.tab-header .dropdown ul li:first-child,
.tab-header .dropdown ul li:last-child {
  background-color: transparent;
  cursor: default;
}

.tab-header .dropdown ul li:not(:first-child):not(:last-child):hover {
  background-color: #eee;
}

.tab-header .dropdown ul li:not(:first-child):not(:last-child):active {
  background-color: #ccc;
}

接下来,在需要使用该组件的地方,比如app.component.html,添加以下代码:


最后,在app.module.ts中将TabDropdownComponent添加到declarations数组中。

现在,您应该能够在应用程序中看到一个包含响应式选项卡和下拉菜单的组件。您可以根据需要自定义样式和功能。

相关内容

热门资讯

必备攻略!wepoker免费透... 必备攻略!wepoker免费透视脚本,pokemmo免费脚本,细节方法(有挂软件);实战中需综合运用...
重大推荐!德普之星辅助器怎么用... 《重大推荐!德普之星辅助器怎么用,wepoker透视脚本苹果版,透明挂教程(有挂攻略)》 德普之星辅...
总算了解!wepoker插件辅... 总算了解!wepoker插件辅助,pokerworld辅助器,透明挂教程(有挂方法);原来确实真的有...
最新通报!pokernow辅助... 最新通报!pokernow辅助工具,拱趴大菠萝万能挂图解,扑克教程(有挂技巧)这是由厦门游乐互动科技...
2024教程!wepoker永... 您好,hhpoker免费透视脚本这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】...
揭秘一下!wepoker开辅助... 揭秘一下!wepoker开辅助能查到吗,hhpoker辅助器,第三方教程(有挂软件);原来确实真的有...
玩家必看教程!pokernow... 自定义aapoker怎么设置提高好牌几率系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑...
推荐十款!大菠萝手游辅助,we... 推荐十款!大菠萝手游辅助,wepoker破解器,技巧教程(有挂透明);1分钟了解详细教程(微信 13...
专业讨论!拱趴大菠萝怎么开挂,... 专业讨论!拱趴大菠萝怎么开挂,wejoker开挂,靠谱教程(有挂透明),支持语音通讯、好友开房及战队...
技巧知识分享!hhpoker买... 技巧知识分享!hhpoker买挂,hhpoker有没有作弊挂,黑科技教程(有挂辅助);原来确实真的有...