我想模仿我在许多 iPhone 应用程序中看到的效果。当单击按钮时,它基本上会将屏幕上的内容从右向左滑动。原始屏幕的内容向左滑动消失,并且下一个屏幕的内容从右侧滑入屏幕中心。
我已经能够使用 jQuery 模拟这个效果。请参见 this fiddle。它可以正常工作,但是随着动画变得更加复杂(例如添加按钮以返回原始屏幕或存在两个以上的屏幕时),这种方法变得非常复杂和混乱。我相信有一种更有效的方法来实现这种效果,但我不知道如何做。有人可以给我一个提示吗?我已经搜索了网络,但我认为我没有使用正确的术语进行搜索,因为我什么也没找到。我的代码如下所示。
HTML:
<div id="screen1">
<div id="header">Screen 1</div>
</div>
<div id="screen2">
<div id="header">Screen 2</div>
</div>
<a href="#" id="button">Swipe</a>
CSS:
body, html {
width: 100%;
height: 100%;
}
#screen1 {
background: blue;
width: 100%;
height: 100%;
position: fixed;
}
#header {
height: 50px;
width: 100%;
background: red;
}
#screen2 {
background: green;
width: 0px;
height: 100%;
position: fixed;
right: 0;
}
jQuery:
$('#button').click(function(){
$('#screen1').animate({width: '0px'});
$('#screen2').animate({width: '100%'});
});