English 中文(简体)
j 拖延——如何停止拖延?
原标题:jQuery delay() - how to stop it?

我已经尝试停止(真实性、真实性)、停止(真实性)和明确Queue(明确);但这只是不了工作。

我对快速变化的滑坡有问题,即已经有一些必须重整一切的职能,但确实没有工作。

function reset(){
   $( div ).clearQueue();
   $( #img ).html(  ).css({ left :0, right :0, opacity :1, z-index :1});
   $( #img2 ).html(  ).css({ left :0, right :0, opacity :1, z-index :1});
   $( #place ).html(  );$( #place ).html( <div id="img"></div><div id="img2"></div> );
}

但是,这等于是停止(或删除)延迟(......)以估计方式运作。 因此,我不知道是否必须使用定时功能。

这里是一纸空文:

reset();
actual_slide=2;
  $( #img ).html( <img src=" +image[4]+ " alt="Obrázek"> ).css({ opacity :0, z-index :2}).delay(time_delay/5).fadeTo(time_fast,1).delay(time_delay*2).fadeTo(time_fast,0);
  $( #img2 ).html( <img src=" +image[3]+ " alt="Obrázek"> ).css({ opacity : 0 , top :0}).fadeTo(time_fast,1).animate({ top : -495 },time_delay*3,function(){
    if(actual_slide==2){$( #img2 ).css({ top :0}).fadeTo(time_fast*2,0).html(  );}else{reset();}
    if(actual_slide==2){$( #img ).html( <img src=" +image[3]+ " id="1" alt="Obrázek"> ).fadeTo(time_fast*2, 1 ).css({ left :-300, top :-700}).animate({ left :-900, top :-700},time_delay*2);}else{reset();}
    if(actual_slide==2){$( #1 ).css({ width :1365, height :1200}).animate({ width :1665, height :1400},time_delay*2);}else{reset();}
  });                          

这种实际的幻灯必须加以保护,然后再重复这一功能,但这也会奏效。 问题在于迅速改变幻灯片,因为重新set头不会停止一切,而是开始做我不想做的事情(如改变其他面貌)。

最佳回答
问题回答

页: 1

这方面的例子

//this is only for make sure that we skip  delay , not other function
var inDelay = false;

function start()
{
    $( .gfx ).animate
    ({
        width: 100
    }, function(){inDelay = true}).delay(3000).animate
    ({
        width: 0
    }, function(){inDelay = false})
}

function breakTheDelay()
{
    if(inDelay)
    {
        $( .gfx ).dequeue();
    }
}

http://jsfiddle.net/wasikuss/5288z/

//edit: more complex example provided with logging timestamps and cleanup ( without cleanup, multiple clicks on Start is unpredictable ) to prove that it works

http://jsfiddle.net/q0058whc/

页: 1

//this is only for make sure that we skip  delay , not other function
var inDelay = false;
var ltime = 0;

// console log will aways show  end  values: 2000, 1000 an 400
// values may be different due to time wasted on calling functions
// sometimes delay is shorten by 0-200ms, it can be caused by js engine probably  

function start()
{
    cleanup();
    ltime = (1*new Date());
    $( .gfx ).queue( fx , function(next)
    {
      logtime(  animate1_start  );
    	$( .gfx ).animate
      ({
          width: 100
      }, 2000, function(){logtime( animate1_end );inDelay = true;})
      next();
    })
    .queue( fx , function(next)
    {
    	logtime( delay_start );
    	next()
    })
    .delay(1000)
    .queue( fx , function(next)
    {
    	logtime( delay_end );
    	next()
    })
    .queue( fx , function(next)
    {
    	logtime( animate0_start );
    	$( .gfx ).animate
      ({
          width: 0
      }, function(){logtime( animate0_end );inDelay = false;})
      next()
    });
}

function cleanup()
{
		// remove current queue
    $( .gfx ).clearQueue()
    // first animate runned interval. stop it 
    .stop()
    // reset width of element
    .css( width ,0)
}

function logtime( name )
{
	var ntime = (1*new Date());
	console.log( name +  :   + ( ntime - ltime ) );
  ltime = ntime;
}

function breakTheDelay()
{
    if(inDelay)
    {
        $( .gfx ).dequeue();
    }
}

//
// version without  inDelay  check only if you know what are you doing
// http://jsfiddle.net/wasikuss/hkw9H/
//
.gfx
{
    background: red;
    width: 0;
    height: 10px
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button onclick="start()">Start</button>
<button onclick="breakTheDelay()">Can t wait!</button>
<div class="gfx"></div>

有一种非常简单的做法,即使用<代码>。 页: 1

我希望用户迅速重新启动一个ation升链,有时在im中。 因此,不使用<代码>delay() I animated to a bogus cs appropriatey {“null”:1}。 这里简单易行。 想为我工作!

//- fade in
$el.stop().animate({"opacity":1}, 200, "easeInSine", function(){
    //- delay for 2000ms
    $el.stop().animate({"null":1}, 2000, function(){
        //- fade out
        $el.stop().animate({"opacity":0}, 1000, "easeInOutSine", function(){
            //- final callback
        });
    });
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签