0

画像を左から右に移動してdivボックスにしようとしていますが、

別のスクリプトを試しました: http://jsfiddle.net/bala2024/MzHmN/

これがhtmlコードです

<!DOCTYPE html>
<html>    
    <head></head>    
    <body style>
        <div id="slideleft" class="slide">
            <button>slide it</button>
            <div class="inner">Slide to the left</div>
            <div style="width:50px; height:50px">
                <img src="sceen.jpg">
            </div>
        </div>
    </body>

</html>

CSS

.slide {
    position: relative;
    background-color: gray;
    height: 100px;
    width: 500px;
    overflow: hidden;
}
.slide .inner {
    position: absolute;
    left: -500px;
    bottom: 0;
    background-color:#e3e3e3;
    height: 30px;
    width: 500px;
}

JS

 $(document).ready(function () {
     $('#slideleft button').click(function () {
         var $lefty = $(this).next();
         $lefty.animate({
             left: parseInt($lefty.css('left'), 10) == 0 ? -$lefty.outerWidth() : 0
         });
     });
 });
4

4 に答える 4

1

メイン コンテナーに幅を適用する必要があります。以下の行に置き換えて、ブラウザで確認してください。

 <div id="slideleft" class="slide" style="width:100px; margin:0 auto">
于 2013-10-03T06:02:21.763 に答える
0

外側のスペースにはマージンを使用し、内側のスペースにはパディングを使用してくださいこれを試してください

<!DOCTYPE html>
<html>
<head>  
</head>
<body style>
    <div id="slideleft" class="slide">
        <button>slide it</button>
        <div class="inner">Slide to the left</div>
        <div style="width:50px; height:50px; margin-left: 100px;"><img src="sceen.jpg">
       </div>         
    </div>   
</body>
</html>
于 2013-10-03T06:04:30.030 に答える
-1

CSS:

div.inner{
background:black;
margin-left:0;
width:100px;
animation:sample 2s;
-webkit-animation:sample 2s;
}
keyframes sample{
from{margin-left:100%;}
to{margin-left:0%;}
}
@-webkit-keyframes sample{
from{margin-left:100%;}
to{margin-left:0%;}
}

フィドル: http://jsfiddle.net/apRMU/17/

于 2013-10-03T06:06:13.463 に答える