题目描述
使用jquery的animate,让两个div叠在一起,点击按钮往上跑,可以看到它们的交界处滚动的非常不雅。图片看不出来可以复制代码到本地。。。
题目来源及自己的思路
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<style type="text/css">
.father{
margin-top: 200px;
margin-bottom: 200px;
}
.son1{
width: 100px;
height: 100px;
background-color: red;
position: relative;
}
.son2{
width: 100px;
height: 100px;
background-color: green;
position: relative;
}
</style>
</head>
<body>
<div class="father">
<div class="son1"></div>
<div class="son2"></div>
</div>
<button>点击</button>
</body>
<script type="text/javascript">
$("button").click(function(){
$(".son1").animate({top:-100},500);
$(".son2").animate({top:-100},500);
})
</script>
</html>
你期待的结果是什么?实际看到的错误信息又是什么?
如何让这两个div很自然向上滚动呢,解决交界处的问题
第一,为什么不用parent去滚动,比两个son自己滚动要好很多。第二:用transition会更合适,你可以试下有没有自然点