0

Web ページにスライド ショーが必要だったので、次のコードを使用しました。

<html>
<head>
<style>
#slideshow {
    position:relative;
    height:350px;

}

#slideshow IMG {
    position:absolute;
    top:0;
    left:0;
    z-index:8;
}

#slideshow IMG.active {
    z-index:10;
}

#slideshow IMG.last-active {
    z-index:9;
}
</style>
<script>
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});
</script>
</head>
<body>
<div id="slideshow" align="middle">
    <img src="img/11.jpg" alt="" class="active"  />
    <img src="img/12.jpg" alt="" />
    <img src="img/13.jpg.jpg" alt=""  />
</div>

</body>
</html>

それは私の画面の左に来ています。しかし、私はそれが私のウェブページの中心に来ることを望んでいました.

誰か教えてください。

ありがとう、よろしく、さびさち

4

4 に答える 4

0


#slideshow#slideshow IMG にいくつかの変更を加えました。div でalign
を 使用しないと思いますが、警告の align 属性が古くなっていることを示しています

<html>
<head>
<style>
#slideshow {
    position:relative;
    height:350px;
    width:500px;
    margin:auto;
}

#slideshow IMG {
    position:absolute;

    z-index:8;
}

#slideshow IMG.active {
    z-index:10;
}

#slideshow IMG.last-active {
    z-index:9;
}
</style>
<script>
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});
</script>
</head>
<body>
<div id="slideshow">
    <img src="img/11.jpg" alt="" class="active"  />
    <img src="img/12.jpg" alt="" />
    <img src="img/13.jpg.jpg" alt=""  />
</div>

</body>
</html>
于 2012-06-11T05:40:56.363 に答える
0

スライドショーは私にはうまくいかないようですが、単純な中央揃えには、スライドショーに幅が必要で、次に margin: 0 auto; だけが必要です。- 左と右の自動は、ここでトリックを行うものです。

そのようです:

#slideshow {
position:relative;
height:350px;
width:350px;
margin:0 auto;
}

html で align="middle" を捨てることができます。

于 2012-06-11T05:37:24.153 に答える
0

である必要がありますがalign="center"、それでも正しくありません。非推奨のタグ属性ではなく、そのようなものには CSS を使用する必要があります。

#slideshow {
   text-align: center;
   margin: 0 auto;
}
于 2012-06-11T05:35:21.417 に答える
0

align属性<div>は非推奨です。

の使用を検討する<div style="text-align:center">か、失敗した場合は、<center>タグの前後に<div>タグを使用してください。

それにもかかわらず、正しいalign属性は"center"not"middle"です。

于 2012-06-11T05:35:27.397 に答える