【发布时间】:2018-03-09 05:27:55
【问题描述】:
这是我的代码。 我的进度条工作正常。它在窗口滚动上显示可移动的进度条。但我希望它在我滚动 div 时移动。 这里我使用的是js查询。
在componentWillmount中写jquery函数也可以吗。
export default class NewPreview extends React.Component {
constructor(props) {
super(props);
self = this;
this.scrollPercent=''
this.xmlType=''
this.d=''
this.c=''
this.state = {
}
}
componentWillMount() {
$(window).scroll(function () {
console.log("h")
var s = $(window).scrollTop()
this.d = $(document).height()
this.c = $(window).height()
this.scrollPercent = (s / (d-c)) * 100;
var position = scrollPercent;
$("#progressbar").attr('value', position);
});
}
render() {
const panel_body = {
borderLeft: "3px solid #00BCD4",
height: "90px",
backgroundColor:"lightyellow",
borderRadius:"4px",
margin:"6px"
}
const progress ={
width:"40%",
position:"fixed",
top:"103px",
backgroundColor:"red"
}
const panel_XML = {
color: "#00BCD4",
fontSize: "17px",
position: "relative",
left: "12px",
top: "10px"
}
if(this.xmlType='slideshow'){
return (
<div id="progressBarID">
<progress style={progress} id="progressbar" value="0" max="100"></progress>
{this.state.newXML.map((data,item)=>
<div class="panel panel-default" style={panel_body}>
<p style={panel_XML}>{data.header}</p>
<p style={panel_XML}>{data.article}</p>
</div>
)}
</div>
)
}
else if(this.xmlType='timeline') {
return(
<div>heloo</div>
)
}
}
}
我应该怎么做才能在我的 div 滚动而不是我的窗口滚动上移动我的进度条。
【问题讨论】:
标签: javascript jquery css reactjs