简体   繁体   English

进度栏如何在div滚动而不是在窗口上移动?

[英]How Progress bar move on div scroll not on window?

Here, My progress bar and that progress bar move when I scroll window. 在这里,当我滚动窗口时,我的进度条和那个进度条会移动。

But I want when I scroll window it detects div not window. 但是我想在滚动窗口时检测到div而不是窗口。 I write code for window and it perfectly worked for on window scroll. 我为窗口编写了代码,它在窗口滚动中完美地工作了。

Here, is my code for perfectly work for window scroll. 这是我的代码,可以完美地用于窗口滚动。 How it moves on div. 它如何在div上移动。 在此处输入图片说明

 $(window).scroll(function () { var scroll = $(window).scrollTop(), documentHeight = $(document).height(), windowHeight = $(window).height(); scrollPercent = (scroll / (documentHeight-windowHeight)) * 100; var position = scrollPercent; $("#progressbar").attr('value', position); }); 
 progress { height: 6px; width: 100%; position:fixed; margin-left: -48px; margin-top: -20px; } 
 <div type="slideshow" id ="slide"> <section> <header>date </header> <section>content</section> </section> <section> <header>date </header> <section>content</section> </section> <section> <header>date </header> <section>content</section> </section> <section> <header>date </header> <section>content</section> </section> </div> 

What should i do to resolve this error. 我应该怎么做才能解决此错误。 Help will be appreciated. 帮助将不胜感激。

here is an example for your question 这是您问题的一个例子

html: 的HTML:

  <div class="parent">
    <div class="child"></div>
  </div>

css: CSS:

.parent{
  width: 100px;
  height: 100px;
  background: red;
  overflow: auto;
}
.child{
  background: rebeccapurple;
  width: 200px;
  height: 200px;
}

the point is set the parent div overflow: auto; 该点设置为父div overflow: auto;

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

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