【发布时间】:2021-05-27 08:14:14
【问题描述】:
我有一个 div 和一些像这样的 scss:
<div class="box">
<h1 id="#h1-1">Title</h1>
<img id="arrowimg"src="img/arrowdown.png"/>
<div class="innerbox">
<nav>
<ul>
<li><a href="#A">A</a></li>
<li><a href="#B">B</a></li>
<li><a href="#C">C</a></li>
</ul>
</nav>
<p> A paragraph within the div</p>
<p>Another paragraph within the div</p>
<p>Yet another paragraph within the div</p>
<div id="B">
<p>Blah blah blah</p>
</div>
<div id="C">
<p>Blah blah blah</p>
</div>
</div>
</div>
SCSS:
.box {
position: absolute;
display:flex;
justify-content: center;
align-items: center;
cursor:pointer;
background-color: rgb(146, 134, 219);
overflow:hidden;
}
img {
position:absolute;
height: 20px;
width: 20px;
top: 760px;
left: 500px;
}
.active {
position:absolute;
background: yellow;
height: 100%;
width: 100%;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
.innerbox {
display:none;
}
我这里有一些 Gsap 代码控制扩展和收缩框 div:
gsap.plugin(ScrollTrigger);
var box = document.querySelector(".box");
var tl = gsap
.timeline({ reversed: true }),
.fromTo(
".box",
{ top: 700, left: 400, height: 50, width: 200 },
{
scrollTrigger: {
trigger: "#arrowimg",
start: "top bottom",
markers: true},
ease: "power3.in",
height: "100%",
width: "100%",
top: 0,
left: 0,
right: 0,
bottom: 0,
duration: 0.45
}
);
显然,我对 Gsap 很陌生。
在我拥有它之前,如果您单击 div,它会扩展和收缩。但它将每次点击注册为一个框点击——即使在导航栏中,所以我决定我应该使用滚动。如果我不能让滚动工作,也许一个按钮会比点击框更好?
这是笔:https://codepen.io/Hamlington/pen/yLVvoQX
任何建议将不胜感激!
谢谢!
【问题讨论】:
-
嘿哈灵顿。请发送minimal, complete, and verifiable example。使用像 CodePen 这样的东西可能是最简单的。我们有 a starter template 来帮助您入门。
-
嗨!对于那个很抱歉。我做了一支小笔,但还是很乱……