0

it isn't a duplicate as I've read the others question but everyone assume that the scroll is vertical, while i need this for horizontal scroll. What i'm trying to do is to scroll a div, placed somewhere in a page, when it reach the center of the screen or it is almost visible, then when it end its scroll i need to continue the page scrolll.

Actually i have a "slider" like this: JSFIDDLE

Actually, I can get an advise when the element is visible on the page after scrolling, but I don't know how to disable vertical scroll, scroll my div, and then scroll page again. The important thing is that the div scroll how much i continue the scrolling (intended with mouse, keyboard and maybe touch, it will be awesome)

function testInView($el){
var wTop = $(window).scrollTop();
var wBot = wTop + $(window).height();
var eTop = $el.offset().top;
var eBot = eTop + $el.height()+50;
return ((eBot <= wBot) && (eTop >= wTop));
}
function setInView(){
$(".slider-wrapper").each(function(){
    var $zis = $(this);
    $zis.removeClass("inview");
    if(testInView($zis)){
       alert("eccolo");   
    }
});
}
$(document).scroll(function(){
    setInView();
});
$(document).resize(function(){
    setInView();
});
$(document).ready(function(){
    setInView();
});

1 Answer 1

0

If you want to disable vertical scrolling then just set overflow-y: hidden on body element

body {
    overflow-y: hidden;
}
3
  • i want to do that but i want to scroll the div when i block the page scroll, and i have to scroll the div instead of scrolling page when it is visible May 28, 2020 at 13:48
  • If you want to scroll the div instead of page then hide the scroll on body and set scroll on div. Use overflow-x and overflow-y property to control scroll on x and y axis. May 28, 2020 at 13:55
  • yes but the div isn't full page, it isn't also full width, so i have to scroll it also if i'm above the page May 28, 2020 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.