{"id":279,"date":"2023-03-07T17:56:34","date_gmt":"2023-03-07T14:56:34","guid":{"rendered":"https:\/\/notes.profidev.online\/?p=279"},"modified":"2023-03-28T23:45:54","modified_gmt":"2023-03-28T20:45:54","slug":"slajder-4","status":"publish","type":"post","link":"https:\/\/notes.profidev.online\/ru\/slider\/279\/","title":{"rendered":"Horizontal slider"},"content":{"rendered":"\n<figure class=\"wp-block-video\"><video height=\"830\" style=\"aspect-ratio: 1437 \/ 830;\" width=\"1437\" controls src=\"https:\/\/notes.profidev.online\/wp-content\/uploads\/2023\/03\/vokoscreenng-2023-03-07_15-49-11.webm\"><\/video><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;cobalt&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}\">&lt;div class=&quot;menu&quot;&gt;\n  &lt;div class=&quot;menu--wrapper&quot;&gt;\n    &lt;div class=&quot;menu--item&quot;&gt;\n      &lt;figure&gt;&lt;img src=&quot;https:\/\/images.unsplash.com\/photo-1595265677860-9a3168007dc0?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=800&amp;q=60&quot; alt=&quot;&quot; \/&gt;&lt;\/figure&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;menu--item&quot;&gt;\n      &lt;figure&gt;&lt;img src=&quot;https:\/\/images.unsplash.com\/photo-1594786118579-95ba90c801ec?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=800&amp;q=60&quot; alt=&quot;&quot; \/&gt;&lt;\/figure&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;menu--item&quot;&gt;\n      &lt;figure&gt;&lt;img src=&quot;https:\/\/images.unsplash.com\/photo-1509339022327-1e1e25360a41?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=800&amp;q=60&quot; alt=&quot;&quot; \/&gt;&lt;\/figure&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;menu--item&quot;&gt;\n      &lt;figure&gt;&lt;img src=&quot;https:\/\/images.unsplash.com\/photo-1525417071002-5ee4e6bb44f7?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=800&amp;q=60&quot; alt=&quot;&quot; \/&gt;&lt;\/figure&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;menu--item&quot;&gt;\n      &lt;figure&gt;&lt;img src=&quot;https:\/\/images.unsplash.com\/photo-1594072702031-f0e2a602dd2c?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=800&amp;q=60&quot; alt=&quot;&quot; \/&gt;&lt;\/figure&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;menu--item&quot;&gt;\n      &lt;figure&gt;&lt;img src=&quot;https:\/\/images.unsplash.com\/photo-1592989819277-a3aafa40c66a?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=800&amp;q=60&quot; alt=&quot;&quot; \/&gt;&lt;\/figure&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;\n\n&lt;script src=&quot;https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/gsap\/3.4.2\/gsap.min.js&quot;&gt;&lt;\/script&gt;\n\/\/\u0421\u043a\u0440\u0438\u043f\u0442 js \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0437\u0434\u0435\u0441\u044c\n\n\/\/\u0410\u0432\u0442\u043e\u0440: Stephen Scaff. @StephenScaff<\/pre><\/div>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;css&quot;,&quot;mime&quot;:&quot;text\/css&quot;,&quot;theme&quot;:&quot;cobalt&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;CSS&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;css&quot;}\">* {\n  box-sizing: border-box;\n}\n\nbody {\n  height: 100vh;\n  overflow: hidden;\n  background: #000;\n  color: #fff;\n  font-family: &quot;Playfair Display&quot;, cursive;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n}\n\n.menu {\n  overflow: hidden;\n  cursor: -webkit-grab;\n  cursor: grab;\n  width: 100%;\n  position: relative;\n  z-index: 1;\n  height: 40vh;\n}\n.menu.is-dragging {\n  cursor: -webkit-grabbing;\n  cursor: grabbing;\n}\n.menu--wrapper {\n  counter-reset: count;\n  display: flex;\n  position: absolute;\n  z-index: 1;\n  height: 100%;\n  top: 0;\n  left: 0;\n  width: 100%;\n}\n.menu--item {\n  counter-increment: count;\n  position: absolute;\n  z-index: 1;\n  top: 0;\n  left: 0;\n  width: 30vw;\n  height: 100%;\n  padding: 0 1.5vw;\n  overflow: hidden;\n}\n@media (max-width: 767px) {\n  .menu--item {\n    width: 40vw;\n    height: 40vw;\n  }\n}\n.menu--item:nth-child(n+10):before {\n  content: counter(count);\n}\n.menu--item figure {\n  position: absolute;\n  z-index: 1;\n  display: block;\n  -webkit-user-select: none;\n     -moz-user-select: none;\n      -ms-user-select: none;\n          user-select: none;\n  -webkit-appearance: none;\n  padding: 0;\n  border: none;\n  outline: none;\n  box-shadow: none;\n  cursor: pointer;\n  width: 100%;\n  height: 100%;\n  overflow: hidden;\n  pointer-events: none;\n  transform-origin: center;\n}\n.menu--item figure img {\n  position: absolute;\n  z-index: 1;\n  top: 0;\n  left: 0;\n  width: 100%;\n  height: 100%;\n  -o-object-fit: cover;\n     object-fit: cover;\n  vertical-align: middle;\n  transform-origin: center;\n}\n.menu--item figure:before {\n  position: absolute;\n  z-index: 2;\n  bottom: 1vw;\n  left: 1vw;\n  display: inline-block;\n  content: &quot;0&quot; counter(count);\n  color: #ffffff;\n  font-size: 3vw;\n}<\/pre><\/div>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;cobalt&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;TrpContentRestriction&quot;:{&quot;restriction_type&quot;:&quot;exclude&quot;,&quot;selected_languages&quot;:[],&quot;panel_open&quot;:true},&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">\/*--------------------\nVars\n--------------------*\/\nconst $menu = document.querySelector('.menu');\nconst $items = document.querySelectorAll('.menu--item');\nconst $images = document.querySelectorAll('.menu--item img');\nlet menuWidth = $menu.clientWidth;\nlet itemWidth = $items[0].clientWidth;\nlet wrapWidth = $items.length * itemWidth;\n\nlet scrollSpeed = 0;\nlet oldScrollY = 0;\nlet scrollY = 0;\nlet y = 0;\n\n\n\/*--------------------\nLerp\n--------------------*\/\nconst lerp = (v0, v1, t) =&gt; {\n  return v0 * (1 - t) + v1 * t;\n};\n\n\n\/*--------------------\nDispose\n--------------------*\/\nconst dispose = scroll =&gt; {\n  gsap.set($items, {\n    x: i =&gt; {\n      return i * itemWidth + scroll;\n    },\n    modifiers: {\n      x: (x, target) =&gt; {\n        const s = gsap.utils.wrap(-itemWidth, wrapWidth - itemWidth, parseInt(x));\n        return `${s}px`;\n      } } });\n\n\n};\ndispose(0);\n\n\n\/*--------------------\nWheel\n--------------------*\/\nconst handleMouseWheel = e =&gt; {\n  scrollY -= e.deltaY * 0.9;\n};\n\n\n\/*--------------------\nTouch\n--------------------*\/\nlet touchStart = 0;\nlet touchX = 0;\nlet isDragging = false;\nconst handleTouchStart = e =&gt; {\n  touchStart = e.clientX || e.touches[0].clientX;\n  isDragging = true;\n  $menu.classList.add('is-dragging');\n};\nconst handleTouchMove = e =&gt; {\n  if (!isDragging) return;\n  touchX = e.clientX || e.touches[0].clientX;\n  scrollY += (touchX - touchStart) * 2.5;\n  touchStart = touchX;\n};\nconst handleTouchEnd = () =&gt; {\n  isDragging = false;\n  $menu.classList.remove('is-dragging');\n};\n\n\/*--------------------\nListeners\n--------------------*\/\n$menu.addEventListener('mousewheel', handleMouseWheel);\n\n$menu.addEventListener('touchstart', handleTouchStart);\n$menu.addEventListener('touchmove', handleTouchMove);\n$menu.addEventListener('touchend', handleTouchEnd);\n\n$menu.addEventListener('mousedown', handleTouchStart);\n$menu.addEventListener('mousemove', handleTouchMove);\n$menu.addEventListener('mouseleave', handleTouchEnd);\n$menu.addEventListener('mouseup', handleTouchEnd);\n\n$menu.addEventListener('selectstart', () =&gt; {return false;});\n\n\n\/*--------------------\nResize\n--------------------*\/\nwindow.addEventListener('resize', () =&gt; {\n  menuWidth = $menu.clientWidth;\n  itemWidth = $items[0].clientWidth;\n  wrapWidth = $items.length * itemWidth;\n});\n\n\n\/*--------------------\nRender\n--------------------*\/\nconst render = () =&gt; {\n  requestAnimationFrame(render);\n  y = lerp(y, scrollY, .1);\n  dispose(y);\n\n  scrollSpeed = y - oldScrollY;\n  oldScrollY = y;\n\n  gsap.to($items, {\n    skewX: -scrollSpeed * .2,\n    rotate: scrollSpeed * .01,\n    scale: 1 - Math.min(100, Math.abs(scrollSpeed)) * 0.003 });\n\n};\nrender();<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":281,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[27,17],"class_list":["post-279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-slider","tag-gsap","tag-jquery"],"_links":{"self":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts\/279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/comments?post=279"}],"version-history":[{"count":0,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/posts\/279\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/media\/281"}],"wp:attachment":[{"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/media?parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/categories?post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.profidev.online\/ru\/wp-json\/wp\/v2\/tags?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}