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 回答
0

点击以下链接观看现场演示...点击这里

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Animation test</title>
<style>

</style>
<script type="text/javascript">
$(document).ready(function() {
    $("#b").animate({left: "+=500"}, 2000);
    $("#b").animate({left: "-=300"}, 1000);
});

</script>
</head>

<body>
<div style="position:relative">
    <div id="b" style="position:absolute;">B</div>
</div>
</body>
</html>
于 2013-10-03T07:07:14.553 回答
-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 回答