0

ページが読み込まれた後、このスクリプトを数秒遅らせようとしましたが、うまくいきませんでした。ここには他にも同様の質問があり、回答が得られているようですが、それらのソリューションを実装しようとしましたが、これまでのところ運がありません.

あなたが提供できる助けに本当に感謝します。前もって感謝します!

<script>
$.fn.rotate = function(){
return this.each(function() {
var $children = $(this).children();
var position = -1;
!function loop() {
    position = (position + 1) % $children.length;
    $children.eq(position)
             .fadeIn(1000)
             .delay(7000)
             .fadeOut(1000, loop);
}();
});
};

function show() {
AB = document.getElementById('.bannergroup');
AB.style.display = 'inline';
}
setTimeout("show()", 5000);

$(function(){
$(".banneritem").hide();
$(".bannergroup").rotate();
});  

</script>
4

2 に答える 2

0

上記のシナリオを見ると、すべての要素がページにロードされたときに関数を呼び出したいと思います。その場合は、次を使用できます。

    $(window).load(function(){
    //executes only when all the elements in the page finish loading like images.
     //write your stuff here 
    });

そうでない場合は、メタダイニングによって提案された回答が役立つはずです。ありがとう

于 2013-08-06T04:33:17.323 に答える
0

この行

$(function () {

より表現力豊かなjQuery(document).ready関数の略で、 DOMContentLoadedイベントを快適にクロスブラウザーで処理します。

jQuery(document).ready(function () {

    // this is the place (to delay something)
    // after page parsed / document ready:
    setTimeout(show, 5000);
});

もう 1 つの読み込みイベントは ( としても知られていますwindow.onload)

jQuery(window).load(function () {

    // this is the place
    // after page and html images are loaded
});

また、(ドットなしで).bannergroup使用する必要がある典型的なクラス識別子で要素を選択しようとしていることがわかります。 しかし、あなたは jQuery を持っているので、簡単にやってみましょう:getElementsByClassName('bannergroup')

function show() {
    $('.bannergroup').css({ display: 'inline' });
    // now .rotate()?
}
于 2013-08-06T04:19:19.013 に答える