JavaScript30之04 – Flex酷炫相册

这篇博客主要探讨了如何利用JavaScript30中的第四课内容,通过掌握和应用Flex布局来创建一个交互式的酷炫相册。文章详细介绍了在实现过程中如何运用CSS选择器和JavaScript的classList.toggle()方法,实现相册图片展示状态的切换,即当元素类名中没有'open-active'时添加,反之则移除。
摘要由CSDN通过智能技术生成

 

主要是学习理解flex。

.panels {
min-height: 100vh; /* 高度为浏览器视窗高度 */
overflow: hidden; /* 隐藏scrollbar */
display: flex;
}
.panel {
background: #6B0F9C;
box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.1);
color: white;
text-align: center;
align-items: center;
/* Safari transitionend event.propertyName === flex */
/* Chrome + FF transitionend event.propertyName === flex-grow */
transition:
font-size 0.7s cubic-bezier(0.61, -0.19, 0.7, -0.11),
flex 0.7s cubic-bezier(0.61, -0.19, 0.7, -0.11),
background 0.2s;
font-size: 20px;
background-size: cover;
background-position: center;
flex-grow: 1; /* flex-grow是它作为item的属性 */
display: flex; /* 这是他作为容器的属性 */
justify-content: center;
align-content: center;
flex-direction: column;
}

 

下面这段运用了一些特别一点的CSS选择器

        /* Flex Children */
        .panel>* { /* 通配符 */
            margin: 0;
            width: 100%;
            transition: transform 2s;
            flex: 1 0 auto;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .panel>*:first-child { /* ">"选择子元素 */
            transform: translateY(-100%); /* 往上偏移它的高度 */
        }
        .panel.open-active>*:first-child {
            transform: translateY(0);
        }
        .panel p:nth-child(2) { /* panel类的 [后代] 中第二个p */
            font-size: 4em;
        }

JavaScript

  1. toggle。 this.classList.toggle(‘open-active’); 相当于如果classList里没有这个class就add,如果有就remove
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值