Javascript 如何使用箭头作为滑动切换指示器? CSS 剧本 HTML
我想在第一个div的末尾添加一个箭头作为指示器,它将随着第二个div的上下滑动而改变Javascript 如何使用箭头作为滑动切换指示器? CSS 剧本 HTML,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想在第一个div的末尾添加一个箭头作为指示器,它将随着第二个div的上下滑动而改变 有人知道怎么做吗?为上下箭头添加两个类,并在heading click函数中切换该类 </head> <body> <div id="main_box">Click to slide up and down</div> <div id="slidingbox"></div> </body> </html> }) /
有人知道怎么做吗?为上下箭头添加两个类,并在heading click函数中切换该类
</head>
<body>
<div id="main_box">Click to slide up and down</div>
<div id="slidingbox"></div>
</body>
</html>
})
//剧本
$(document).ready(function() {
$(".option-content").hide();
$(".arrow-up").hide();
$(".option-heading").click(function(){
$(this).next(".option-content").slideToggle(500);
$(this).find(".arrow-up, .arrow-down").toggle();
});
<body>
<div class="active" id="main_box">Click to slide up and down</div>
<div id="slidingbox"></div>
</body>
})
您可以在第一个div中的arrow之后添加伪元素,然后为up和down创建两个类 //html
$(document).ready(function() {
$(".option-content").hide();
$(".arrow-up").hide();
$(".option-heading").click(function(){
$(this).next(".option-content").slideToggle(500);
$(this).find(".arrow-up, .arrow-down").toggle();
});
创建两个具有上下箭头背景图像的类。在第一个div的末尾添加一个div,其中包含任意一个类。现在使用toggleClass在同一个click事件上切换向上和向下箭头类。
$(document).ready(function() {
$(".option-content").hide();
$(".arrow-up").hide();
$(".option-heading").click(function(){
$(this).next(".option-content").slideToggle(500);
$(this).find(".arrow-up, .arrow-down").toggle();
});
$(document).ready(function() {
$(".option-content").hide();
$(".arrow-up").hide();
$(".option-heading").click(function(){
$(this).next(".option-content").slideToggle(500);
$(this).find(".arrow-up, .arrow-down").toggle();
});
<body>
<div class="active" id="main_box">Click to slide up and down</div>
<div id="slidingbox"></div>
</body>
$(document).ready(function() {
$("#main_box").on("click",function(){
$("#slidingbox").slideToggle('fast',function(){
if ($('#slidingbox').is(':hidden')) {
$("#main_box").removeClass('active')
$("#main_box").addClass('in-active')
}
else{
$("#main_box").removeClass('in-active')
$("#main_box").addClass('active')
}
});
});
});