0

テキストのブロックを自動的に「入力」するjQueryプログラムを作成しています。ユーザーが「テキストをクリアして機能を再開する」機能を再開できるようにしようとしています。これを行う方法がわかりません。コードは次のとおりです。

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()で関数を停止する必要があると思います。その後、すべてを再起動します。しかし、どうすればいいのかわかりません。どんな助けでも素晴らしいでしょう。-ありがとう!

4

1 に答える 1

0

間隔を使用しているので、その間隔をよりグローバルにスコープされた変数に保存します。

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

このように、[再起動]ボタンをクリックすると、次のことができます。

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

それがいくらか役立つことを願っています!

于 2012-07-24T02:34:51.627 に答える