gpt4 book ai didi

javascript - ToggleClass 链接到 Canvas 外的单个 div?

转载 作者:太空宇宙 更新时间:2023-11-04 12:17:59 25 4
gpt4 key购买 nike

我在一个页面上有多个图像,我希望每个图像在点击时都链接到 Canvas 外的单独页面。目前,每个图像都链接到同一页面,我想弄清楚如何分别点击每个图像。我已经简化了下面的代码,但这里是完整 Pen 的链接:http://codepen.io/anon/pen/KwQYvm?editors=110

<div class="container">

<section id="slider">
<div id="section-1" class="fullpage">
<a href="#slider">
<h1>Header</h1>
<a href="#" class="menu-close">⇉</a>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quo aliquid iste consectetur incidunt dolorem inventore rerum, tempore quis nulla iure eveniet nostrum, saepe itaque mollitia modi ex. Cum, nam odio.</p>
</div>

<div id="section-2" class="fullpage">
<a href="#slider">
<h1>Header</h1>
<a href="#" class="menu-close">⇉</a>
<p>porem ipsum dolor sit amet, consectetur adipisicing elit. Quo aliquid iste consectetur incidunt dolorem inventore rerum, tempore quis nulla iure eveniet nostrum, saepe itaque mollitia modi ex. Cum, nam odio.</p>
</div>
</section>

<ul id="images">
<li><a href="#section-1" class="menu-link"><img src="https://placekitten.com/g/200/300" alt="" /></a></li>
<li><a href="#section-2" class="menu-link"><img src="https://placekitten.com/g/200/300" alt="" /></a></li>
</ul>

</div><!--container-->

CSS:

.container {
background: gray;
-webkit-transition: 1.15s ease;
-moz-transition: 1.15s ease;
-o-transition: 1.15s ease;
transition: 1.15s ease;
}

#slider {
position: absolute;
top: 0;
bottom: 0;
left: -100%;
width: 100%;
height: 100%;

-webkit-transform: translate(0px, 0px);
-moz-transform: translate(0px, 0px);
-o-transform: translate(0px, 0px);
-ms-transform: translate(0px, 0px);
transform: translate(0px, 0px);
-webkit-transition: 1.15s ease;
-moz-transition: 1.15s ease;
-o-transition: 1.15s ease;
transition: 1.15s ease;
}

#slider > div {
position: absolute;
}

.container.active {
-webkit-transform: translate(100%, 0);
-moz-transform: translate(100%, 0);
-o-transform: translate(100%, 0);
-ms-transform: translate(100%, 0);
transform: translate(100%, 0);
}

.fullpage {
height: 100vh;
}

还有 JS:

$('.menu-link').click(function() {
$('#slider').toggleClass('active');
$('.container').toggleClass('active');
});

$('.menu-close').click(function() {
$('#slider').toggleClass('active');
$('.container').toggleClass('active');
});

最佳答案

你可以做什么:

1) 隐藏两个部分,为每个部分添加 hidden

.hidden{  visibility:hidden;  }
...
<div id="section-1" class="fullpage hidden">
<div id="section-2" class="fullpage hidden">

2) 当点击.menu-link 时,您需要显示相应的部分。在这里您可以使用您的链接指向它的事实:

$('.menu-link').click(function() {
$('#slider').toggleClass('active');
$('.container').toggleClass('active');
$($(this).attr('href')).removeClass('hidden');//here you find the section and make it visible
});

3) 您需要在单击menu-close 时将其隐藏起来,对于menu-close,目标部分是其父级,因此您可以这样做:

$('.menu-close').click(function() {
$('#slider').toggleClass('active');
$('.container').toggleClass('active');
$(this).parent().addClass('hidden');//here you hide the section
});

关于javascript - ToggleClass 链接到 Canvas 外的单个 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28550955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com