gpt4 book ai didi

javascript - 如何知道是否所有匹配的元素都已使用 slideUp 隐藏

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

我这里有这个测试:http://jsbin.com/epihis/2/edit

我有三个段落,单击时会一个接一个地向上滑动。隐藏所有段落后,我想显示一个按钮来向下滑动它们。

我该怎么做?

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){

//jQuery mouseover function
$("p#hovercolor").mouseover(function(){
$("p#hovercolor").css("background-color","yellow");
});

//jQuery mouseout function
$("p#hovercolor").mouseout(function(){
$("p#hovercolor").css("background-color","green");
});

//jQuery click function
$('input[name="Colorbtn"]').click(function(){
$('.myBox').css('background', '#00aeef');
$('.myBox').css('color', '#fff');
});

$('input[name="discolorbtn"]').click(function(){
$('.myBox').css('background', '#fff');
$('.myBox').css('color', '#000');
});

//Hide the matched elements with a sliding motion.
$('p.sliderhider').click(function(){
$(this).slideUp();
});


});

</script>
</head>
<body>

<p id="hovercolor">Move the mouse pointer over this paragraph.</p>

<div class="myBox" style="border:1px solid blue; width:150px; height:150px; margin-bottom:20px;">
BOX 1
</div>

<input type="button" value="Color myBox" name="Colorbtn"/>
<input type="button" value="Dis-Color myBox" name="discolorbtn"/><br /><br />
<hr>
<p class="sliderhider" style="display:block; background: yellow; width:200px">Slide this up one at a time</p>
<p class="sliderhider" style="display:block; background: yellow; width:200px">Slide this up one at a time</p>
<p class="sliderhider" style="display:block; background: yellow; width:200px">Slide this up one at a time</p>

</body>
</html>

最佳答案

尝试:

 $('p.sliderhider').click(function () {
$(this).slideUp(function () {
if ($('p.sliderhider:visible').length === 0) {
$('hr').after('<button id="show">Button</button>')
};
});
});
$(document).on('click', '#show', function () {
$('p.sliderhider').show();
})

jsFiddle example

在 slideUp 的回调中,您可以检查可见段落的长度,当没有剩余时,生成按钮以再次显示它们。

关于javascript - 如何知道是否所有匹配的元素都已使用 slideUp 隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16864360/

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