先引入jquery,这是肯定的。
然后准备好结构,设计思路有很多种,不嫌麻烦的话可以做复杂点的计算,可以让隐藏的效果做的更加逼真,大致思路就是定位,宽度和位置的同时变化。
在这里我介绍的是一个投机取巧的办法,俩框。
只需要用js来控制其left值即可。
测试通过,复制可用,望采纳。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title></title>
<script src="
http://code.jquery.com/jquery-latest.js"></script> <style>
.wrap{position: relative;width: 100px;height: 100px;border: 1px solid #ddd;overflow: hidden;}
.box{width: 100px;height: 100px;position: absolute;top: 0;left: 0;background: #d00;}
</style>
</head>
<body>
<div class="wrap">
<div class="box"></div>
</div>
<script>
$(function(){
$('.wrap').click(function(){
$('.box').animate({left:'100px'}, 500);
});
});
</script>
</body>
</html>