The*_*hew 3 javascript css jquery scroll
var pagestart = 0;
var currentlyat = pagestart;
var lastScrollTop = 0;
$(document).ready(function(){
function scrollPageTo(a){
if(a == 0){
$('#top').show();
$('#top').animate({
top: 0
}, 1000, function(event){
$('#page').css('top', $(window).height()).hide();
});
}
else
{
$('#page').hide();
$('#page').animate({
top: 0
}, 1000, function(event){
$('#top').css('top', $(window).height()).hide();
});
}
}
if(pagestart == 0){
$('#top').css('height', $(window).height());
$('#page').hide();
}
else
{
$('#top').hide();
$('#page').css('height', $(window).height());
}
$(window).scroll(function(){
if(currentlyat == 0){
if(($(this).scrollTop() < lastScrollTop) && $(this).scrollTop() == 0){
scrollPageTo(1);
}
}
else
{
if(($(this).scrollTop() > lastScrollTop) && $(this).scrollTop() == 0){
scrollPageTo(0);
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
http://jsbin.com/uZiDaXud/1/edit
我想要做的是创建类似于MEGA.co.nz网站的系统,例如本页面.
基本上是两个容器,两个单独的页面.一个进入#top,另一个进入#page.pagestart确定它是否应该以#top或开头#page.#top始终与用户的窗口具有相同的高度(因此没有滚动条).当您在#top激活时向下滚动,或单击某处的链接时,#top将向上滚动屏幕上方并#page从底部向上滚动.当#page活动时(可能比用户的窗口更高),并且您位于页面顶部然后仍然向上滚动(或单击链接),#page将向下滚动屏幕下方并#top从顶部向下滚动.
这会产生一个页面,当你向下滚动时,一个动画开始移动#top到屏幕上方#page然后调出,然后你就可以正常滚动了.当您处于页面顶部并向上滚动时,#top将再次弹出.
很难解释,这就是为什么我建议点击这个并将其视为MEGA.co.nz已实现它.
我怎样才能达到这个效果?
*使用jQuery鼠标滚轮插件
HTML结构
<div id="wrapper">
<div id="splash">
<div id="splash-footer">Show content</div>
</div>
<div id="content">
<div id="content-header">Show splash</div>
<div><!-- content here --></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
/* css normalized */
html, body {
height:100%;
width:100%;
overflow:hidden;
}
#wrapper {
height:100%;
}
#splash {
position:relative;
background-color:#cce;
height:100%;
}
#splash-footer {
position:absolute;
bottom:0;
width:100%;
}
#content {
position:relative;
height:100%;
overflow:auto;
}
#content-header {
position:absolute;
top:0;
width:100%;
}
Run Code Online (Sandbox Code Playgroud)
jQuery的
/* scroll events */
$("#splash").on("mousewheel", function (e) {
if (e.deltaY <= 0) {
$('#splash').animate({
height: 0
}, 500);
}
});
$("#content").on("mousewheel", function (e) {
if (e.deltaY > 0 && $(this).scrollTop() <= 0) {
$('#splash').animate({
height: '100%'
}, 500);
}
});
/* click events */
$("#splash-footer").on("click", function () {
$('#splash').animate({
height: 0
}, 500);
});
$("#content-header").on("click", function () {
$('#splash').animate({
height: '100%'
}, 500);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2055 次 |
| 最近记录: |