S
S
swks2015-11-17 16:24:08
css
swks, 2015-11-17 16:24:08

How to implement horizontal movement with vertical scrolling?

tYByv2rjUz0.jpg
How to implement horizontal movement with vertical scrolling, so that the movement would occur in a straight line and in one block, and not occur throughout the page?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
hime2, 2015-11-17
@swks

Read here I
also advise you to read about scrollleft
Here is another option
https://github.com/kasparsj/jquery-data-parallax here is a ready-made example, but it lags, it seems to me.

L
LightAir, 2015-11-17
@LightAir

https://css-tricks.com/snippets/jquery/horz-scroll...

D
Denis, 2015-11-17
@Deonisius

If I understand correctly, then in principle, you can screw it here, the solution that I gave to a similar question . Only replace scrollTop with scrollLeft Sandbox
example
UPD jsfiddle.net/27mz45L2/1

var elH = horizontal.offsetHeight,
    elTop = horizontal.offsetTop,
    winH = window.innerHeight,
    factor = horizontal.scrollWidth / (elH * 2 + winH);
window.addEventListener('scroll', function (e) {
    var elPosTop = horizontal.getBoundingClientRect().top + elH,
        elPosBot = horizontal.getBoundingClientRect().bottom - elH;
    if ((elPosTop >= 0) && (elPosBot <= winH)) {
        var dE = document.documentElement,
            top = (this.pageYOffset || dE.scrollTop) - (dE.clientTop || 0);
        horizontal.scrollLeft = Math.abs(elTop - winH - top) * factor;
    }
}, false);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question