-
-
Save chayn1k/7452658 to your computer and use it in GitHub Desktop.
горизонтальный скролл по колонкам
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
<link href="style.css" rel="stylesheet"> | |
<script src="main.js"></script> | |
</head> | |
<body> | |
<div id='container'> | |
<article> | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc libero magna, venenatis quis aliquet et, | |
rutrum in augue. Donec vel tempor dolor. Donec volutpat fringilla porta. Suspendisse non nulla tortor. | |
Quisque commodo ornare mi, sit amet aliquet justo bibendum non. Integer bibendum convallis sapien, sit | |
amet tincidunt orci placerat in. Integer vitae consequat augue. | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc libero magna, venenatis quis aliquet et, | |
rutrum in augue. Donec vel tempor dolor. Donec volutpat fringilla porta. Suspendisse non nulla tortor. | |
Quisque commodo ornare mi, sit amet aliquet justo bibendum non. Integer bibendum convallis sapien, sit | |
amet tincidunt orci placerat in. Integer vitae consequat augue. | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc libero magna, venenatis quis aliquet et, | |
rutrum in augue. Donec vel tempor dolor. Donec volutpat fringilla porta. Suspendisse non nulla tortor. | |
Quisque commodo ornare mi, sit amet aliquet justo bibendum non. Integer bibendum convallis sapien, sit | |
amet tincidunt orci placerat in. Integer vitae consequat augue. | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc libero magna, venenatis quis aliquet et, | |
rutrum in augue. Donec vel tempor dolor. Donec volutpat fringilla porta. Suspendisse non nulla tortor. | |
Quisque commodo ornare mi, sit amet aliquet justo bibendum non. Integer bibendum convallis sapien, sit | |
amet tincidunt orci placerat in. Integer vitae consequat augue. | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc libero magna, venenatis quis aliquet et, | |
rutrum in augue. Donec vel tempor dolor. Donec volutpat fringilla porta. Suspendisse non nulla tortor. | |
Quisque commodo ornare mi, sit amet aliquet justo bibendum non. Integer bibendum convallis sapien, sit | |
amet tincidunt orci placerat in. Integer vitae consequat augue. | |
= | |
</article> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var __scrolled, | |
$container = document.querySelector('#container'), | |
$article = document.querySelector('article') | |
; | |
$container | |
.addEventListener('scroll', deferPosition, false); | |
document.body.addEventListener('mouseup', function(){ | |
__scrolled && doPosition(); | |
}, true); | |
function deferPosition(){ | |
__scrolled = true; | |
} | |
function doPosition(){ | |
__scrolled = false; | |
var vw = $container.offsetWidth, | |
cw = $article.offsetWidth / 5, | |
width = $article.offsetWidth, | |
left = $container.scrollLeft, | |
index = Math.round(left / cw) | |
; | |
$container.scrollLeft = cw * index; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
article { | |
-webkit-column-count:5; | |
-webkit-column-width: 100%; | |
-webkit-column-rule: 1px solid red; | |
width: 500% | |
} | |
#container { | |
overflow: auto; | |
height: 150px; | |
width: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment