1

私は(助けを借りて)うまく機能するjQueryスクリプトを作成しましたが、クリック機能を使用せずにそれ自体を自動化/アニメーション化する必要があります。これが可能かどうかを知りたいだけです。スライドショーに似ています。

基本的に、このコードでは、クラス/ ID名などの要素のリストを変更しながら、画像をクリックしてDIVを表示/非表示にすることができます。

これが私のコードです:

JQUERY:

jQuery(document).ready(function(){
    //if this is not the first tab, hide it
    jQuery(".imgs:not(:first)").hide();
    //to fix u know who
    jQuery(".imgs:first").show();
    //when we click one of the tabs
    jQuery(".img_selection a").click(function(){
        //get the ID of the element we need to show
        stringref = jQuery(this).attr("href").split('#')[1];

        // adjust css on tabs to show active tab
        $('.img_selection a').removeAttr('id'); // remove all ids
        $(this).attr('id', this.className + "_on") // create class+_on as this id.
        //hide the tabs that doesn't match the ID
        jQuery('.imgs:not(#'+stringref+')').hide();
        //fix
        if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0") {
            jQuery('.imgs#' + stringref).show();
        } else
            //display our tab fading it in
            jQuery('.imgs#' + stringref).show();
        //stay with me
        return false;
    });
});
4

2 に答える 2

2

これでうまくいくはずです。それはすべての「タブ」を取得し、各クリックの間に2秒(2000ms)の休止を伴う循環順序でimをクリックします

var tabs = jQuery(".img_selection a");
var len = tabs.size();
var index = 1;
function automate() {
    tabs.eq((index%len)).trigger('click');
    index++;
}
var robot = setInterval(automate, 2000);

//if at some point you want to stop the automation just call
clearInterval(robot);

デモを作成しました

http://jsbin.com/urulo/2/(http://jsbin.com/urulo/2/コードの編集

于 2010-03-17T16:04:20.140 に答える
1

Javascriptでは、関数の実行を時間制限することはできません。

しかし、HTML5は、基本的にバックグラウンドワーカースレッドであるWebワーカーをもたらします。一定時間後にWebワーカーを一時停止することができます。

于 2010-03-17T14:04:22.767 に答える