WEB第四次作业

作业分析

选项卡开发 2025-03-23 191101.png

代码演示

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡</title>
    <style>

        /* 公共样式 */
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        html,body{
            width: 100%;
            height: 100%;
        }
        html{
            font-size: 10px;
        }

        /* 样式绘制选项卡区域 */
        .tab{
            width: 40rem;
            height: 30rem;
            border:solid 2px oldlace;
            border-radius: 8px;
            overflow: hidden;
        }
        .tab-tittle{
            width: 100%;
            height: 5rem;
            display: flex;
            justify-content:space-between;
            border-bottom: solid 1px oldlace;
        }
        .tt{
            border-right: solid 1px oldlace;
            text-align: center;
            width: 33%;
            height: 5rem;
            line-height: 5rem;
            font-size: 1.8rem;
            cursor: pointer;
        }
        .tab-tittle .tt:last-child{
            border-right: none;
        }
        .tt:hover{
            background-color: oldlace;
            color: white;
        }
        .tab-content{
            height: 100%;
            width: 100%;
            position: relative;
            overflow: hidden;
            background-color: azure;
        }
        .tab-content .tc{
            width: 100%;
            height: 100%;
            color: white;
            font-size: 1.6rem;
            text-align: center;
            position: absolute;
            display: none;
        }
        .tc:nth-of-type(1){
            background-color: aqua;
            display: block;
        }
        .tc:nth-of-type(2){
            background-color: bisque;
        }
        .tc:nth-of-type(3){
            background-color:beige;
        }
    </style>
</head>
<body>
    <div class="tab">
        <!-- 标题 -->
        <div class="tab-tittle">
            <div class="tt active">标题1</div>
            <div class="tt">标题2</div>
            <div class="tt">标题3</div>
        </div>
        <!-- 内容 -->
        <div class="tab-content">
            <div class="tc">内容1</div>
            <div class="tc">内容2</div>
            <div class="tc">内容3</div>
        </div>
    </div>

    <!-- JS代码 -->
    <script>
        //获取所有的标题标签
        let tts = document.getElementsByClassName("tt")

        //循环给每个标题添加事件
        for(let i = 0;i < tts.length;i ++){
            //给每个标题添加鼠标进入事件
            tts[i].onmouseenter = function(){
                console.log("鼠标进入了第" + i + "个标题")
                //获取所有的内容标签
                let tcs = document.getElementsByClassName("tc")

                //隐藏所有的内容标签
                for( let j = 0;j < tts.length;j ++){
                tcs[j].style.display = "none"
                }

                //显示和标题编号相同的内容标签
                tcs[i].style.display="block"

                //高亮对应标题:取消所有标题的高亮
                for(let x=0;x<tts.length;x ++){
                tts[x].classList="tt"
                }
                //让对应编号的标题,添加active名称
                tts[i].classList="tt active"
            }
        }
    </script>
</body>
</html>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 项目要求 模仿小鹅通首页页面,完整开发页面效果 小鹅通首页图片-样式图 代码示例 使用Trae CN工具进行编写,...
    MoonArchive阅读 1,076评论 0 1
  • 第四次作业 作业: 爬取大数据专题所有文章列表,并输出到文本中保存。 每篇文章需要爬取的数据:作者、标题、文章地址...
    mudu86阅读 3,180评论 3 1
  • 开放大学学习心得体会写作辅导讲义 一、看清题目明确要求 二、下载附件看格式要求 三、综合大作业说明 综合练习大...
    金牌教育咨询阅读 17,115评论 0 2
  • 当前文档版本:v1.3 更新日志: v1.3添加了第一题的提示 v1.2修复了参考资料的“邻接链表-BFS”代码的...
    XXX_f47c阅读 5,864评论 1 2
  • 白天把易经画图作业写了,晚上把本周王阳明的打卡完成。明天要回老家,今天晚上的任务就是把编程作业补上一点,否则就没有...
    晴空00阅读 1,450评论 0 0

友情链接更多精彩内容