百度錢包:
http://1.baidu.com/?invite_code=KMC5HS3E&qq-pf-to=pcqq.group
想知道 Js 是怎么樣寫的!然后自己仿作一個!
閉關(guān)修行中......
最好的學習方式還是打開開發(fā)者工具,然后一邊交互一邊觀察 dom 的變化
記得有一篇文章提過,這種設計方式是違反網(wǎng)頁設計初衷,我個人也覺得有點這種感覺,本來是自由滾動的卻被死死地固定了。偶爾用幾個還行,用多了真的不是一種好趨勢。
說了這么多,給你個DEMO吧。以前找到的~
http://www.thepetedesign.com/demos/onepage_scroll_demo.html#
如果沒錯的話就是這種效果~
用純 CSS 實現(xiàn)了一個:https://bumfo.github.io/parallax.html
鑑於使用了 position: sticky,目前只支持 Firefox/Safari。其它瀏覽器需要 JS 的 polyfill。
polyfill 如下:
var Sticky = function() {
var s = [],
support = (function testSupport() {
var p = document.createElement("p");
var st = ["sticky", "-webkit-sticky"];
return st.some(function(x) {
p.style.position = x;
return p.style.position === x;
});
}());
function Sticky(o) {
var self = this;
s.push(self);
self[0] = o;
var placeholder = document.createElement("p");
self.placeholder = placeholder;
placeholder.classList.add("placeholder");
self.fixed = false;
self.posit = posit;
function posit() {
var rect;
if (self.fixed) {
rect = placeholder.getBoundingClientRect();
self.staticTop = rect.top + window.pageYOffset;
} else {
rect = o.getBoundingClientRect();
self.staticTop = rect.top + window.pageYOffset;
}
}
posit();
}
Sticky.prototype.stick = function() {
if (support)
return;
var o = this[0],
top = this.staticTop;
var placeholder = this.placeholder, fixed = this.fixed;
console.log(top);
if (top > window.pageYOffset && fixed) {
placeholder.parentNode.removeChild(placeholder);
o.classList.remove("sticky");
fixed = false;
} else if (top <= window.pageYOffset && !fixed) {
o.parentNode.insertBefore(placeholder, o);
o.classList.add("sticky");
fixed = true;
}
this.fixed = fixed;
};
if (!support) {
window.addEventListener("scroll", function() {
s.forEach(function(x) { x.stick(); });
});
window.addEventListener("resize", function() {
s.forEach(function(x) { x.posit(); });
s.forEach(function(x) { x.stick(); });
});
} else {
console.log("support");
}
return Sticky;
}();