分享一個來自corpse的固定背景滾動特效
HTML
代碼如下:<div id="cbp
<nav>
<a href="#fbsection
<a href="#fbsection
<a href="#fbsection
<a href="#fbsection
<a href="#fbsection
</nav>
<section id="fbsection
<section id="fbsection
<section id="fbsection
<section id="fbsection
<section id="fbsection
</div>
CSS
/* Set all parents to full height */
html
height:
}
/* The nav is fixed on the right side and we center it by translating it
(we don
position: fixed;
z
right:
top:
transform: translateY(
}
display: block;
position: relative;
color: transparent;
height:
}
content:
position: absolute;
width:
height:
border
border:
}
background: rgba(
}
background: #fff;
}
/* background
position: relative;
background
background
background
background
}
#fbsection
background
}
#fbsection
background
}
#fbsection
background
}
#fbsection
background
}
#fbsection
background
}
Javascript
/**
* cbpFixedScrollLayout
*
*
* Licensed under the MIT license
*
*
* Copyright
*
*/
var cbpFixedScrollLayout = (function() {
// cache and initialize some values
var config = {
// the cbp
$sections : $(
// the navigation links
$navlinks : $(
// index of current link / section
currentLink :
// the body element
$body : $(
// the body animation speed
animspeed :
// the body animation easing (jquery easing)
animeasing :
};
function init() {
// click on a navigation link: the body is scrolled to the position of the respective section
config
scrollAnim( config
return false;
} );
//
// First one when we scroll down: the current navigation link gets updated
// A `new section′ is reached when it occupies more than
// Second one when we scroll up: the current navigation link gets updated
// A `new section′ is reached when it occupies more than
config
if( direction ===
}
if( direction ===
}
// on window resize: the body is scrolled to the position of the current section
$( window )
scrollAnim( config
} );
}
// update the current navigation link
function changeNav( $section ) {
config
config
config
}
// function to scroll / animate the body
function scrollAnim( top ) {
config
}
return { init : init };
})();
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20507.html