DOM
smoth scrolling
利用动画间隔收集并translate滚动元素,相当于纯css实现的顺滑滚动。
虽然挺顺滑,但让人头昏。
https://tympanus.net/Tutorials/SmoothScrollAnimations/
https://tympanus.net/codrops/2019/07/10/how-to-add-smooth-scrolling-with-inner-image-animations-to-a-web-page/
// SmoothScrollclass SmoothScroll {constructor() {// the <main> elementthis.DOM = {main: document.querySelector('main')};// the scrollable element// we translate this element when scrolling (y-axis)this.DOM.scrollable = this.DOM.main.querySelector('div[data-scroll]');// the items on the pagethis.items = [];this.DOM.content = this.DOM.main.querySelector('.block--story');[...this.DOM.content.querySelectorAll('.block__item')].forEach(item => this.items.push(new Item(item)));// here we define which property will change as we scroll the page// in this case we will be translating on the y-axis// we interpolate between the previous and current value to achieve the smooth scrolling effectthis.renderedStyles = {translationY: {// interpolated valueprevious: 0,// current valuecurrent: 0,// amount to interpolateease: 0.1,// current value setter// in this case the value of the translation will be the same like the document scrollsetValue: () => docScroll}};// set the body's heightthis.setSize();// set the initial valuesthis.update();// the <main> element's style needs to be modifiedthis.style();// init/bind eventsthis.initEvents();// start the render looprequestAnimationFrame(() => this.render());}update() {// sets the initial value (no interpolation) - translate the scroll valuefor (const key in this.renderedStyles ) {this.renderedStyles[key].current = this.renderedStyles[key].previous = this.renderedStyles[key].setValue();}// translate the scrollable elementthis.layout();}layout() {this.DOM.scrollable.style.transform = `translate3d(0,${-1*this.renderedStyles.translationY.previous}px,0)`;}setSize() {// set the heigh of the body in order to keep the scrollbar on the pagebody.style.height = `${this.DOM.scrollable.scrollHeight}px`;}style() {// the <main> needs to "stick" to the screen and not scroll// for that we set it to position fixed and overflow hiddenthis.DOM.main.style.position = 'fixed';this.DOM.main.style.width = this.DOM.main.style.height = '100%';this.DOM.main.style.top = this.DOM.main.style.left = 0;this.DOM.main.style.overflow = 'hidden';}initEvents() {// on resize reset the body's heightwindow.addEventListener('resize', () => this.setSize());}render() {// Get scrolling speed// Update lastScrollscrollingSpeed = Math.abs(docScroll - lastScroll);lastScroll = docScroll;// update the current and interpolated valuesfor (const key in this.renderedStyles ) {this.renderedStyles[key].current = this.renderedStyles[key].setValue();this.renderedStyles[key].previous = MathUtils.lerp(this.renderedStyles[key].previous, this.renderedStyles[key].current, this.renderedStyles[key].ease);}// and translate the scrollable elementthis.layout();// for every itemfor (const item of this.items) {// if the item is inside the viewport call it's render function// this will update item's styles, based on the document scroll value and the item's position on the viewportif ( item.isVisible ) {if ( item.insideViewport ) {item.render();}else {item.insideViewport = true;item.update();}}else {item.insideViewport = false;}}// loop..requestAnimationFrame(() => this.render());}}
HTTP
POST & GET
GET 的 URL 会存在浏览器历史及WEB服务器日志里;
POST 不会;
GET应该用于处理,只读的操作,无副作用(操作数据库)。这样请求可被CDN缓存。
POST则可用于带副作用的操作。
所以,只取值,用GET,其他用POST。既省资源也安全。
