【发布时间】:2018-03-30 03:43:26
【问题描述】:
我有一个 div,当我在这个 div 上滚动时,位于页面顶部的进度条会在其中发生一些事件。
当我的光标在滚动时检测到我的 div 然后我的进度条 div 显示,否则它仍然隐藏。
所以最后我希望我的 div 上没有溢出,但是当我滚动窗口时,我的进度条会移动。
在这里,请查看我的代码,我们将不胜感激。
$('#slide').scroll(function () {
var scroll = $(this).scrollTop();
var scroll_height = $(this).get(0).scrollHeight;
var height = $(this).height();
var percent = scroll / (scroll_height - height) * 100;
$("#progressbar").attr('value', percent);
});
$(window).scroll(function() {
if(isOnScreen($("#slide"))){
$("#progressbar").show();
console.log("dikhgya");
} else {
$("#progressbar").hide();
console.log("nhi");
}
});
var para = document.createElement("Progress");
para.setAttribute('id', 'progressbar');
para.setAttribute('value', 0);
para.setAttribute('max', 100);
document.getElementById("slide").appendChild(para);
progress {
height: 6px;
top: 46px;
left: 0px;
width: 100%;
/* bottom: 1326px; */
position: fixed;
margin-left: -1px;
margin-top: -1px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div type="timeline" id="slide">
<section>
<header>Title one</header>
<article> Content</article>
</section>
<section>
<header>Title two</header>
<article> Content</article>
</section>
<section>
<header>Title three</header>
<article> Content</article>
</section>
<section>
<header>Title four</header>
<article> Content</article>
</section>
</div>
【问题讨论】:
-
求助有人在吗?
标签: javascript jquery css progress-bar scrollbar