仅在切换类时显示标题和段落
show heading and paragraph only when toggle a class?
我想显示class="label"测试1,2,3,4"和标题2"一些文本"https://i.stack.imgur.com/mgerO.jpg仅当点击".card.selected"时
我想只在点击一个名为".card.selected"的类时显示"标题2"和段落?
这是我的代码
<!DOCTYPE html>
<html>
<head>
<script src="classie.js"></script>
<script src="https://github.com/desandro/classie/blob/master/classie.js"></script>
<style>
#main {
width: auto
height: auto
border: 1px solid #c3c3c3;
display: -webkit-flex;
-webkit-flex-direction: column;
display: flex;
flex-direction: column;
margin:10px;
}
#main div {
width: 150px;
height: 90px;
display:block;
}
.card-container {
height: 400px;
perspective: 600;
position: relative;
width: 150px;
}
.card {
height: 100%;
position: absolute;
transform-styvle: preserve-3d;
transition: all 0.5s ease-in-out;
width: 100%;
}
.card.selected {
transform: translatey(-90px);
z-index: 99;
}
.card .side {
backface-visibility: hidden;
height: 100%;
position: absolute;
width: 100%;
}
.
#card-container: div {
width: 150px;
height: 90px;
display:block;
}
.label {
border: 1px solid black;padding: 2px;margin: 0;
font-size: 250%;
float:left;
background-color: red;
}
.button{
float:left;
}
#main img {
border: 1px solid green;padding: 2px;margin: 0;
padding: 1px;
margin: 10;
width: 400px;
height:400px;
display:inline;
}
h2 {
padding:0 5px;
position: absolute;
top: 40px;
text-align: center;
width: 100%;
}
</style>
</head>
<body>
<div id="main">
<div >
<div class="card" onclick="myFunction(this)">
<div class="side">
<p class="label"> test 1 </p>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29841/jimmy.jpg" alt="person 1 ">
<h2>some text </h2>
</div>
</div>
</div>
<div >
<div class="card" onclick="myFunction(this)">
<div class="side">
<p class="label"> test 2 </p>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29841/jimmy.jpg" alt="person 1 ">
<h2>some text </h2>
</div>
</div>
</div>
<div >
<div class="card" onclick="myFunction(this)">
<div class="side">
<p class="label"> test 3 </p>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29841/jimmy.jpg" alt="person 1 ">
<h2>some text </h2>
</div>
</div>
</div>
<div >
<div class="card" onclick="myFunction(this)">
<div class="side">
<p class="label"> test 4 </p>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29841/jimmy.jpg" alt="person 1 ">
<h2>some text </h2>
</div>
</div>
</div>
<div >
<div class="card" onclick="myFunction(this)">
<div class="side">
<p class="label"> test 5 </p>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29841/jimmy.jpg" alt="person 1 ">
<h2>some text </h2>
</div>
</div>
</div>
<div >
<div class="card" onclick="myFunction(this)">
<div class="side">
<p class="label"> test 6 </p>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/29841/jimmy.jpg" alt="person 1 ">
<h2>some text </h2>
</div>
</div>
</div>
</div>
<script>
function myFunction(el) {
classie.toggle(el, "selected" )// toggle class
}
</script>
</body>
</html>
这可能就是您需要的
$('.card').click(function (el) {
$(el.currentTarget).toggleClass('selected');
console.log($(el.currentTarget));
})
和
.card .label, .card h2 {
display: none;
}
.card.selected .label, .card.selected h2 {
display: block;
}
完整代码:https://jsfiddle.net/tomi77/a0yxkqyh/
相关文章:
- 当我悬停使用php连接到mysql的图像时显示标题
- 如何使用 bootstrap3 和 php 突出显示标题中的活动页面
- chart js:如何显示标题或标签
- 从下拉菜单选项中显示“标题”标签
- 如何在可展开菜单中正确显示标题
- Spotify 应用程序 - 列表不显示播放列表的曲目,只显示标题
- 在 asp.net 中使用 javascript 显示标题属性消息
- 引导灯箱:显示标题属性中的图像说明
- 在浏览器的选项卡中显示标题
- 如何按焦点在 HTML 元素上显示标题
- 加载随机背景音乐并显示标题
- 如何使用ES6 angular 1.3控制器显示标题
- 在图像下方垂直和水平居中显示标题
- 如何使用d3.js在SVG图表上居中显示标题
- 在网页上显示标题或替换文本
- 如何有一个淘汰网格显示标题和基于下拉结果的数据
- 谷歌地图显示标题的信息框
- 仅在切换类时显示标题和段落
- JQuery在图像悬停显示标题标签内容,可能的
- JQuery周日历:在初始加载时只显示标题