2012-07-24 3 views
0

나는 자동으로 텍스트 블록을 입력하는 jQuery 프로그램을 작성 중이다. 사용자가 "텍스트 지우기 및 기능 다시 시작"기능을 다시 시작하도록 허용하려고합니다.이 작업을 수행하는 방법을 잘 모르겠습니다. 코드는 다음과 같습니다.jQuery 함수를 다시 시작하십시오. onClick

var char = 0; 
var caption = ""; 
var standby 

// initiate the Cursor 

$(document).ready(function() { 
    setInterval ("cursorAnimation()", 600); 
}); 

// initiate the Text 

$(document).ready(function() { 
    $('#abouttext').aboutText(); 
}); 


// The typing animation 

function aboutText() { 
    $('#abouttext').html(caption.substr(0, captionLength++)); 
    if(captionLength < caption.length+1){ 
     setTimeout("type()",50); 
    }else{ 
     captionLength = 0; 
     caption = ""; 
    } 
} 

// The Restart Button 

function restart() { 
    $('#restartbtn').click(function() { 
     var typing = $('#abouttext'); 
    } 
     typing.stop(); 



// The cursor animation 

function cursorAnimation() { 
    $('.cursor').animate({ 
     opacity : 0 
    }, "fast", "swing").animate({ 
     opacity : 1 
    }, "fast", "swing"); 
} 

stop() 함수를 중지해야합니다. 그 후 모든 것을 다시 시작하십시오. 하지만 어떻게해야할지 모르겠다. 어떤 도움이라도 굉장합니다. -감사! 잘

답변

0

당신이 간격을 사용하고 있기 때문에이, 그 간격이 더 세계적 범위 변수에 저장 될 수있다 :

var typeThings = setInverval(function() { 'your func here' }, 50); 

이 다시 시작 버튼이 방법은 당신이 할 수있는 클릭

clearInterval(typeThings); // stop the typing 
$('#abouttext').html(''); // clear original text 
callYourOriginalFunction(); // call the function again 

희망을 그 다소 도움이된다!

관련 문제