滚动页面然后在certian位置滚动元素

Reg*_*ins 9 html javascript css

我对如何做到这一点感到有点失落.

我有一个网页.我希望用户向下滚动,然后在距离顶部特定距离处我希望鼠标滚动以实现元素位置(使其看起来像是元素滚动).然后,当该元素到达某个位置时(即顶部:-500),我希望滚动再次应用于主网页.有关如何做到这一点的任何想法?

我现在正在努力工作,但没有任何运气,我会在有东西展示时发布

编辑:解决方案/ sudo代码的开头https://jsfiddle.net/vk0jk37v/23/

附件是我正在申请这个的一个区域的图像.

//pageFeature.style.backgroundPosition = "0px " + parseInt(-y / 6) + 'px'); 

var element = document.getElementById('container').getBoundingClientRect();
var elementTop = element.top //distance from top 720;

// variable to stop function from being replayed on scroll when scrolling image
var isScrollingImage = false;

// disables scroll on body
var disableScroll = function() {
    document.body.style.overflow='hidden';
}
// enables scroll on body
var enableScroll = function() {
    document.body.style.overflow='auto';
}
//change position of background along y axis with scroll
var scrollImage = function() {
    console.log("called");
   isScrollingImage = true;
   var pageFeature = document.getElementById("inner");
   var pageFeaturePosition;
   pageFeature.style.backgroundPositionY=parseInt(-scrollY / 10) + "px";
    //if (background is scrolled to bottom) {
    //    enableScroll();
    // }
}

//when element gets to center of viewport and animation is scroll is not on element
//call scrollImage()
function checkPosition() {
    if (scrollY > 720 && !isScrollingImage) {
        disableScroll();
        scrollImage();
    }
    //isScrollingImage = false;
}

//once out of view port will have to bring the image back down, 
//scroll image will only happen on the way down

document.addEventListener('scroll', checkPosition);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Ben*_*nny 3

    var thresholdY = 150; 
    var thresholdCounter = 0; 
    var speed = 4; 
    var element = document.getElementById('yourElement'); 

    window.onscroll = function(event) { 
      if(scrollY > thresholdY) { 
        window.scrollTo(0, thresholdY); 
        element.setAttribute('style', 'transform:translate3d(0,' + (--thresholdCounter * speed) + 'px,0);'); 
        return false; 
      }
      return null; 
    }; 
Run Code Online (Sandbox Code Playgroud)

这是一个演示: https: //jsfiddle.net/pkt6xnb5/

这里的想法是,当用户到达某个阈值 Y 位置时,将窗口保持在适当的位置。同时,我们沿着 Y 轴向用户滚动的相反方向变换元素,使其在用户进一步向下滚动时向上移动。这就是您要找的吗?