我试图隐藏我的文本一段时间然后使用函数显示。目前它眨眼我不想让它隐藏等待几秒然后显示。
setTimeout(function() {
$('.hotKeys').hide();
$('.shortcut').hide();
}, 5000);
$(document).ready(function() {
var $hotKeys = $('.hotKeys');
var $shortcut = $('.shortcut');
function runIt() {
$hotKeys.animate({
opacity: '0.6'
}, 1000);
$hotKeys.animate({
opacity: '0'
}, 1000, runIt);
$shortcut.animate({
opacity: '0.6'
}, 1000);
$shortcut.animate({
opacity: '0'
}, 1000, runIt);
}
runIt();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h4 class="hotKeys">hot keys</h4>
<ul class="shortcut">
<li>h</li>
<li>p</li>
<li>s</li>
<li>c</li>
</ul>
</div>
&#13;
我尝试将隐藏功能放在代码的不同区域,我认为&#39; .delay()&#39;会做到这一点,但我似乎无法弄明白。
答案 0 :(得分:1)
您可以使用解决方案https://jsfiddle.net/bvxft9de/1/
$(document).ready(function() {
$('.hotKeys').hide();
$('.shortcut').hide();
var $hotKeys = $('.hotKeys');
var $shortcut = $('.shortcut');
function runIt() {
$('.hotKeys').show();
$('.shortcut').show();
$hotKeys.animate({opacity:'0.6'}, 1000);
$hotKeys.animate({opacity:'0'}, 1000, runIt);
$shortcut.animate({opacity:'0.6'}, 1000);
$shortcut.animate({opacity:'0'}, 1000, runIt);
}
setTimeout(function(){
runIt();
}, 2000);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h4 class="hotKeys">hot keys</h4>
<ul class="shortcut">
<li>h</li>
<li>p</li>
<li>s</li>
<li>c</li>
</ul>
&#13;
最初,您的文字将被隐藏2秒,然后它将开始动画。
希望这会对你有所帮助。
答案 1 :(得分:0)
您可能想要使用setTimeout
例如:
var milliseconds = 1000; //1 sec
setTimeout(function runIt() {
$hotKeys.animate({opacity:'0.6'}, 1000);
$hotKeys.animate({opacity:'0'}, 1000, runIt);
$shortcut.animate({opacity:'0.6'}, 1000);
$shortcut.animate({opacity:'0'}, 1000, runIt);
},milliseconds );
答案 2 :(得分:0)
exec cmd.exe /psexec \\ip -u admin -p password cmd.exe
setTimeout(function(){
$('.hotKeys').show();
$('.shortcut').show();
}, 5000);
$(document).ready(function() {
$('.hotKeys').hide();
$('.shortcut').hide();
var $hotKeys = $('.hotKeys');
var $shortcut = $('.shortcut');
function runIt() {
$hotKeys.animate({opacity:'0.6'}, 1000);
$hotKeys.animate({opacity:'0'}, 1000, runIt);
$shortcut.animate({opacity:'0.6'}, 1000);
$shortcut.animate({opacity:'0'}, 1000, runIt);
}
runIt();
});
答案 3 :(得分:0)
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
&#13;
$(document).ready(function() {
var $hotKeys = $('.hotKeys');
var $shortcut = $('.shortcut');
function runIt() {
$hotKeys.animate({
opacity: '0.6'
}, 1000);
$hotKeys.animate({
opacity: '0'
}, 1000);
$shortcut.animate({
opacity: '0.6'
}, 1000);
$shortcut.animate({
opacity: '0'
}, 1000);
}
runIt();
setInterval(function() {
if($('.hotKeys').is(':visible') && $('.shortcut').is(':visible')) {
$('.hotKeys').hide();
$('.shortcut').hide();
}
else
{
$hotKeys.animate({
opacity: '1'
}, 1000);
$hotKeys.animate({
opacity: '1'
}, 1000);
$shortcut.animate({
opacity: '1'
}, 1000)
$shortcut.animate({
opacity: '1'
}, 1000);
$('.hotKeys').show();
$('.shortcut').show();
}
}, 3000);
});
&#13;
试试吧。它不是闪烁