我所做的点击功能会改变内容。但是,每当我使用setinterval
或settimeout
时,函数会运行一次,然后立即再次运行而不使用延迟。
我做错了什么?
$(document).ready(function() {
$('.seashellcontainertwo').hide();
var settimer = 1;
$('.seashellcontainer').click(function() {
settimer = 0;
$('.seashellcontainer').hide();
$('.seashellcontainertwo').show();
});
$('.seashellcontainertwo').click(function() {
settimer = 0;
$('.seashellcontainertwo').hide();
$('.seashellcontainer').show();
});
if (settimer == 1) {
setInterval(function() {
$('.seashellcontainertwo').hide();
$('.seashellcontainer').show();
}, 3000);
setInterval(function() {
$('.seashellcontainertwo').show();
$('.seashellcontainer').hide();
}, 3000);
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="seashellcontainer">seashellcontainer</div>
<div class="seashellcontainertwo">seashellcontainertwo</div>
&#13;
答案 0 :(得分:0)
我想,这是您在let filtered = someNSArray.filteredArrayUsingPredicate(predicate)
中尝试实现的目标,但不确定intervals
事件。进一步澄清将有所帮助。
click
$(document).ready(function() {
var seaShellContainerTwo = $('.seashellcontainertwo');
var seaShellContainer = $('.seashellcontainer');
seaShellContainerTwo.hide();
var settimer = 0;
setInterval(function() {
if (settimer === 1) {
seaShellContainerTwo.hide();
seaShellContainer.show();
settimer = 0;
} else {
seaShellContainerTwo.show();
seaShellContainer.hide();
settimer = 1;
}
}, 3000);
});