简体   繁体   English

如何模拟人为的ajax搜索?

[英]How can I emulate a factitious ajax search?

All I want to do is this: reducing the opacity of an element and increasing it again after a short time. 我要做的就是:减少元素的不透明度,并在短时间后再次增加它。 So I don't want to send any ajax request. 所以我不想发送任何ajax请求。 Just I want to make a delay. 我只是想拖延一下。

Something like this: 像这样:

 $('button').on('click', function(){ $('.search_result').animate({ opacity: 0.3, }, 50); /* I need a delay here */ $('.search_result').animate({ opacity: 1, }, 50); }) 
 p { border-bottom: 1px solid; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" /> <button>seach</button> <div class="search_result"> <p>post1</p> <p>post2</p> <p>post3</p> <p>post4</p> </div> 

As you see that process happens so fast. 如您所见,该过程是如此之快。 How can I implement a delay on the way of it? 如何在途中实施延误? In other word how can I make it slow? 换句话说,我该如何使其变慢?

You can use delay(1000) in jquery to chain the methods. 您可以在jquery中使用delay(1000)来链接方法。

 $('button').on('click', function() { $('.search_result').animate({ opacity: 0.3, }, 50).delay(1000) .animate({ opacity: 1, }, 50); }) 
 p { border-bottom: 1px solid; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" /> <button>seach</button> <div class="search_result"> <p>post1</p> <p>post2</p> <p>post3</p> <p>post4</p> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM