简体   繁体   English

根据滚动条设置div的位置

[英]Set the position of div according to scroll

I want a div to be scroll upto some height with scrolling. 我希望div通过滚动向上滚动到某个高度。

I am using this code bt its not working for me,please help me out to solve this problem using javascript or css i can't use jquery in my programm thanks in advance 我正在使用此代码bt它对我不起作用,请帮助我使用javascript或css解决此问题,我无法在程序中使用jquery预先感谢

 element.style.position='fixed';
 element.style.scrollTop ='800px';
 element.style.overflow='scroll';

 function Scroll()
  {
    var intY = document.getElementById("impulseadcontainer").scrollTop ;
    console.log("pos"+intY);
  }

You have to assign something to the scrollTop attribute in order for it to work. 您必须为scrollTop属性分配一些内容才能使其正常工作。

function scroll() {
    document.getElementById("impulseadcontainer").scrollTop = 0; // scrolls to top (set here whatever value you want)
}

You can do this with the following javascript code. 您可以使用以下JavaScript代码执行此操作。

document.scrollTo(0,document.getElementById('id-of-element').offsetTop); document.scrollTo(0,的document.getElementById( '元素的id-的-')的offsetTop。);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM