我在一个页面上有多个图像,我希望点击时每个图像链接到画布上的单独页面。目前,每张图片都链接到同一页面,我想知道如何分别点击每张图片。我已经简化了下面的代码,但这里是完整笔的链接: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');
});
答案 0 :(得分:1)
你能做什么:
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
});