CSS 工具条缩放(无需图标的三角形切换icon)

效果

代码

html

<div :class="[`index-tool`, showTools ? '' : 'hidden-right-border']" >
    <!-- 收缩按钮 -->
    <div class="visible-btn" @click="showTools=!showTools">
        <div :class="['tangle', showTools ? 'left-tangle' : 'right-tangle']"></div>
    </div>
    <!-- 工具条 -->
    <div v-show="showTools" v-for="(item,index) in icons" :key="index" :title="item.label" class="btn">
        <img src="../assets/images/test.png" >
    </div>
</div>

CSS

  • 代码 25 行,设置三角形的高宽为 5px;
  • 代码 29 - 36,用于切换三角形;
  • 代码 55 - 62,隐藏后将工具条放在 right=100px 固定位;
.index-tool{
    position absolute
    top: 93px;
    left:  50%;
    right: unset;
    transform: translateX(-50%)
    z-index 999
    width max-content
    display flex
    flex-direction row
    color:#ffffff;
    background-color:rgba(0, 61, 61, 0.8);
    border:1px solid #0d8a72;
    .visible-btn {
        display: inline-block;
        width: 14px;
        height: 47px;
        border-right: 1px solid #0d8a72;
        cursor: pointer;
        .tangle {
            display: inline-block;
            height: 0;
            width: 0;
            border-style: solid;
            border-width: 5px 5px 5px 5px;
            margin-top: 17px;
            
        }
        .left-tangle {
            margin-left: 5px;
            border-color: rgba(0,0,0,0) rgba(0,0,0,0) rgba(0,0,0,0) #e2eaf3;
        }
        .right-tangle {
            // margin-left: 5px;
            border-color: rgba(0,0,0,0) #e2eaf3 rgba(0,0,0,0) rgba(0,0,0,0);
        }
    }
    .btn {
        width: 66px;
        height: 47px;
        text-align: center;
        cursor: pointer;
        img {
            margin-top: 8px;
        }
        .label {
            font-size:15px;
            transform: scale(0.8);
            letter-spacing: 1px;
            margin-top: 3px;
            text-shadow: 0px 4px 6px rgba(0,0,0,.4 );
        }
    }
}
.hidden-right-border {
    border-right: none;
    border-radius:0;
    padding-right: 0;
    left: unset;
    transform: none;
    right: 100px;
}

源码

<template>
	<div class="tool">
		<div :class="[`index-tool`, showTools ? '' : 'hidden-right-border']" >
            <!-- 收缩按钮 -->
            <div class="visible-btn" @click="showTools=!showTools">
                <div :class="['tangle', showTools ? 'left-tangle' : 'right-tangle']"></div>
            </div>
            <!-- 工具条 -->
            <div v-show="showTools" v-for="(item,index) in icons" :key="index" :title="item.label" class="btn">
                <img src="../assets/images/test.png" >
            </div>
        </div>
	</div>
</template>
<script>
export default {
	data() {
		return {
            showTools: true,
            icons: [
                {
                   label: '测试 01 ' 
                },
                {
                   label: '测试 01 ' 
                },
                {
                   label: '测试 01 ' 
                },
                {
                   label: '测试 01 ' 
                },
                {
                   label: '测试 01 ' 
                },
                {
                   label: '测试 01 ' 
                },
            ]

		}
	}
}
</script>
<style lang="stylus" scoped>
.index-tool{
    position absolute
    top: 93px;
    left:  50%;
    right: unset;
    transform: translateX(-50%)
    z-index 999
    width max-content
    display flex
    flex-direction row
    color:#ffffff;
    background-color:rgba(0, 61, 61, 0.8);
    border:1px solid #0d8a72;
    .visible-btn {
        display: inline-block;
        width: 14px;
        height: 47px;
        border-right: 1px solid #0d8a72;
        cursor: pointer;
        .tangle {
            display: inline-block;
            height: 0;
            width: 0;
            border-style: solid;
            border-width: 5px 5px 5px 5px;
            margin-top: 17px;
            
        }
        .left-tangle {
            margin-left: 5px;
            border-color: rgba(0,0,0,0) rgba(0,0,0,0) rgba(0,0,0,0) #e2eaf3;
        }
        .right-tangle {
            // margin-left: 5px;
            border-color: rgba(0,0,0,0) #e2eaf3 rgba(0,0,0,0) rgba(0,0,0,0);
        }
    }
    .btn {
        width: 66px;
        height: 47px;
        text-align: center;
        cursor: pointer;
        img {
            margin-top: 8px;
        }
        .label {
            font-size:15px;
            transform: scale(0.8);
            letter-spacing: 1px;
            margin-top: 3px;
            text-shadow: 0px 4px 6px rgba(0,0,0,.4 );
        }
    }
}
.hidden-right-border {
    border-right: none;
    border-radius:0;
    padding-right: 0;
    left: unset;
    transform: none;
    right: 100px;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值