Tag: 延迟

如何暂停javascript直到完成某事?

为了尽可能快,我现在就会跳到这个话题。 我想在加载jQuery之前延迟脚本。 这是我的问题:我有代码在jQuery尚未加载时自动插入jQuery.js : if(typeof jQuery==”undefined”) { var s=document.createElement(“script”); s.type=”text/javascript”; s.async=true; s.src=”http://code.jquery.com/jquery-1.5.1.min.js”; var x=document.getElementsByTagName(“script”)[0]; x.parentNode.insertBefore(s, x); } $(document).ready(function() { //My code goes here, right? }); 它完美地插入脚本,但问题是$(document).ready()不会等到脚本完全加载,它会在加载脚本时立即跳转。 我想暂停,我该怎么办?

在触发第三个函数之前等待两个异步函数的结束(jQuery Deferred?)

我试图理解jQuery的Deferred ,但是尽管有样本,我无法实现我想做的事情。 所以,我想异步调用2个函数,当BOTH结束时,再调用另一个函数。 这是我的代码 function1(); function2(); function3(); function1()和function2()对我的ASP.NET应用程序进行ajax调用,它们完美地工作。 它们必须在function3()开始之前结束。 我正在阅读并再次阅读文档,但function3()不等待其他两个人的结束。 你能否提供我的一些样本以便我了解Deferred ? 我真的需要他们来完成我项目的一个重要部分。 非常感谢你。 奖金问题 我已经读过了.when延迟…有可能写一些 元素,比如运行function1() ,然后运行 function2() ……等等? UPDATE 关于function1()和function2()更多细节:它们非常相似,这里是它们的主体: function function1() { return $.ajax({ url : “@Url.Action(“MyMethod”, “MyController”)”, contentType : “application/json; charset=utf-8”, dataType : “json” }).done(function(data) { $.each(data, function(index) { pushDatas(data[index]); }) }).fail(function (result) { alert(“function1failed”); }); } function pushDatas(data) { if(!($.inArray(data, […]

Jquery:如何同时进行连续和同时动画

我想要一个屏幕元素(其ID为#sign1 )以正弦波移动。 为此我需要连续向上和向下’摆动’,同时它同时向右移动。 但我并不真正了解队列 ,这对于连续的动画来说是非常必要的。 我可以同时做2 个动画。 。 。 例如,同时向上和向右移动, 通过将queue: false放在两者上, 我可以做两个连续的动画,。 。 。 例如,向上移动,然后向下移动, 通过链接.delay(1000).queue(function(n) {在它们之间 。 。 。 但我似乎无法做三次或更多连续摆动,同时向右移动。 在下面,你看,我可以得到2次向下摆动,跳过它们之间的向上摆动,这奇怪地不起作用。 此外,这是它的小提琴: JS小提琴 使用Javascript //MOVE RIGHT FOR 7 seconds: $(“#sign1”).animate( {left: ‘+=80%’}, { duration: 7000, queue: false } ); //WOBBLE DOWN for 1 second $(“#sign1”) .animate( { top: ‘+=15%’}, { duration: 1000, queue: […]

jQuery幻灯片显示不同的延迟时间

我使用了Innerfade和Cycle,但我有几个div需要淡入,暂停和淡出,但我想以不同的速率暂停不同的幻灯片,因为有些内容会比其他幻灯片更多。 我没有看到我如何通过Innerfade或Cycle实现这一目标。 我尝试过这个,但所有事件都会立即触发。 Content1 Content2 Content3 Content4 Content5 $(“#slide1”).fadeIn(‘slow’); $(“#slide1”).delay(5000).fadeOut(‘slow’); $(“#slide2”).fadeIn(‘slow’); $(“#slide2”).delay(5000).fadeOut(‘slow’); $(“#slide3”).fadeIn(‘slow’); $(“#slide3”).delay(10000).fadeOut(‘slow’); $(“#slide4”).fadeIn(‘slow’); $(“#slide4”).delay(5000).fadeOut(‘slow’); $(“#slide5”).fadeIn(‘slow’); $(“#slide5”).delay(5000).fadeOut(‘slow’); 所以在这种情况下,我希望在5秒后淡出每张幻灯片,但幻灯片3应该保持10秒钟。 我怎么能做到这一点? 谢谢你提供的所有帮助!

Jquery图像fadein延迟X

如何让我的图像一个接一个地出现? 我目前正在使用Jquery fadein使我的图像淡化,但我希望它们在不同的时间开始。 无论如何我可以延迟图像淡入? 很快? $(document).ready(function(){ window.onload = function() { $(‘.fader1’).hide().fadeIn(3000); $(‘.fader2’).hide().fadeIn(9000); $(‘.fader3’).hide().fadeIn(6000); }; });

使用setTimeout延迟jQuery动画

当用户按下按钮移动到下一个图像时,我正在处理图像上的一些转换。 当彼此相邻的多个图像非常窄时,这些图像将同时转换。 因此,我检查图像上的宽度,并将薄的数据添加到数组中,然后对数组中的每个对象运行转换。 我想在数组中每个图像的动画之间创建一点延迟,所以我试图在1秒超时后运行我的jQuery.animate。 以下是我试图让超时工作失败的方法: 1。 for (i=0; i < set.length; i++) { if (i != 0) { setTimeout(function() { set[i].transitionOut($('#gallery'), 562) }, 100); } else { set[i].transitionOut( $('#gallery'), 562 ); } } 2。 for (i=0; i < set.length; i++) { if (i != 0) { function tempTransition() { set[i].transitionOut( $('#gallery'), 562 ); } setTimeout(tempTransition, […]

如何使用Jquery下拉菜单延迟隐藏菜单?

我有一个工作正常的下拉菜单,但我希望如此,如果我将鼠标hover在菜单上,它不会立即再次隐藏。 所以基本上我想要一秒钟的延迟。 我读过有关setTimeout的内容,但不确定它是否是我需要的? $(‘#mainnav a’).bind(‘mouseover’, function() { $(this).parents(‘li’).children(‘ul’).show(); }); $(‘#mainnav a’).bind(‘mouseout’, function() { $(this).parents(‘li’).children(‘ul’).hide(); });

具有多个延迟的YDN-DB

我试图使用多个延迟与jquery $ .when,但到目前为止没有运气,这是我的代码: var req = $.when(db.count(‘items’),db.values(‘items’),db.get(‘config’, 1)); req.done(function(count,r,config) { var currency = config.currency; if(count > 0){ var n = r.length; for (var i = 0; i < n; i++) { var id = r[i].id; var itemId = r[i].itemId; console.log('ID: '+id+' itemID: '+itemId+' Currency: '+currency); } } }); 我的样本没有用,所以希望你们能帮助我,我到处寻找解决方案。 谢谢

为什么我的jQuery when()。then()函数在ajax请求完成之前触发?

我需要设置异步回调,因为函数从远程位置获取内容。 我这样做: $.when( priv[box.view.renderWith](content, box.view.gadget_id) ).then(function(late) { console.log(“done”); console.log(late) console.log($(content)) $(content).append(late).enhanceWithin(); }); 使用my when函数触发单个Ajax请求。 在它的回调中,我正在返回一个元素以附加到$(content) 。 我的问题是, then函数在我的ajax回调运行之前很久then触发并返回一些东西。 问题 : 是否无法使用带有ajax请求的函数的when() ? 我是否必须在when()直接发出ajax请求? 或者为什么then()马上触发? 我怎么能解决这个问题? 谢谢! 编辑:我当前版本的代码段: $.when( priv[box.view.renderWith](content, box.view.gadget_id) ).then(function(fragment) { // DOM manip… console.log(“NOW WE ARE DONE WITH WHEN”); console.log(fragment) $(content).append(fragment).enhanceWithin(); }); 而函数,我正在调用(没有内容生成部分): priv.constructListbox = function (element, internal) { var no_data_body, no_data_cell, portable, […]

在while循环中延迟

所以我想在jquery中做一个延迟的ajax请求,直到我收到一个特定的服务器响应(非null)。 我该怎么做呢? while (data.response != null) { $.ajax(..).done(function(data); } function doUntilResult() { Server.doA().done(function(data) { Server.doB(data).done(function(result) { //if result == null, repeat again }); }); }