- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 NPM 包 ( https://github.com/ryanhefner/react-scroll-trigger ) 来处理我正在构建的新网站上的一些动画。我正在使用
onEnter
和
onExit
还好。不过,我想使用
onProgress
prop 在不同时间触发窗口中的多个动画,并在滚动时更改它们。我需要将它们附加到滚动位置。但是,作为 JS 的新手,我并不完全理解该包所写的内容以及如何使用 onProgress 来告诉我的函数进度的值是什么。有人可以帮助我理解我应该如何使用它吗?
...
const AppContainer = styled.div`
width: 100%;
`;
const Section1 = styled.div`
width: 100%;
height: 100vh;
background-color: lightgray;
`;
const Section2 = styled.div`
width: 100%;
height: 500px;
display: flex;
align-items: center;
justify-content: center;
`;
const Heading = styled.h1`
font-size: 50px;
color: #270d61;
opacity: ${props => props.visible === true ? "1" : "0"};
transition: opacity 5000ms;
`;
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
visible: false,
}
};
onProgress = () => {
//some functions here
};
render () {
return (
<AppContainer>
<Section1/>
<Section2>
<Heading visible={this.state.visible}>
<ScrollTrigger onProgress={this.onProgress()}/>
What's Up?
</Heading>
</Section2>
</AppContainer>
)
}
}
export default App;
最佳答案
看起来像 <ScrollTrigger />
组件旨在包裹内容。 ScrollTrigger
无非是一个div
根据 div
的位置启动杂项事件相对于视口(viewport)。
这是一个应该对您有用的小演示...它展示了如何使用 onProgess
, onEnter
,和onExit
事件(高级别)..
注意:我必须在新选项卡中打开 CodeSandbox 窗 Eloquent 能正常工作... you can try this link - 如果这不起作用,只需在新选项卡中打开沙盒 URL..
希望这有帮助!
代码:
export default class AppScroller extends Component {
state = {
cssworld: "",
cssfadein: "",
progress: 0
};
onEnterViewport = () => {
console.log("entered");
this.setState({
cssworld: "world",
cssfadein: "fadeInText"
});
};
onExitViewport = () => {
console.log("exited");
this.setState({
cssworld: "",
cssfadein: ""
});
};
onProgress = e => {
this.setState({
progress: e.progress.toFixed(2)
});
};
render() {
const { progress, cssworld, cssfadein } = this.state;
return (
<div
style={{
height: "2000px",
display: "flex",
alignItems: "center"
}}
>
<ScrollTrigger
style={{
border: "2px solid green",
height: "10%",
width: "100%"
}}
onEnter={this.onEnterViewport}
onExit={this.onExitViewport}
onProgress={this.onProgress}
>
<div style={{ display: "inline-block" }}>
<img
alt="world"
className={cssworld}
style={{ width: "100px" }}
src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Erioll_world_2.svg/256px-Erioll_world_2.svg.png"
/>
</div>
<div style={{ display: "inline-block" }}>
<p className={cssfadein}>This is some text to fade in!</p>
</div>
<div
style={{
top: 0,
left: 0,
position: "fixed"
}}
>
Progress: {progress * 100}%
</div>
</ScrollTrigger>
</div>
);
}
}
CSS
.world {
-webkit-animation: spin1 5s linear;
-moz-animation: spin1 5s linear;
-o-animation: spin1 5s linear;
-ms-animation: spin1 5s linear;
animation: spin1 5s linear;
display: block;
}
@-webkit-keyframes spin1 {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@-moz-keyframes spin1 {
0% {
-moz-transform: rotate(0deg);
}
100% {
-moz-transform: rotate(360deg);
}
}
@-o-keyframes spin1 {
0% {
-o-transform: rotate(0deg);
}
100% {
-o-transform: rotate(360deg);
}
}
@-ms-keyframes spin1 {
0% {
-ms-transform: rotate(0deg);
}
100% {
-ms-transform: rotate(360deg);
}
}
@keyframes spin1 {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.fadeInText {
margin-top: 25px;
font-size: 21px;
text-align: center;
animation: fadein 5s;
-moz-animation: fadein 5s; /* Firefox */
-webkit-animation: fadein 5s; /* Safari and Chrome */
-o-animation: fadein 5s; /* Opera */
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@-moz-keyframes fadein {
/* Firefox */
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@-webkit-keyframes fadein {
/* Safari and Chrome */
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@-o-keyframes fadein {
/* Opera */
from {
opacity: 0;
}
to {
opacity: 1;
}
}
关于javascript - 在react-scroll-trigger中使用onProgress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57403709/
我已经实现了从 Internet 下载文件的代码,但在使用进度值(进度百分比)更新 GUI 线程时遇到空指针异常。 这是我的代码。 public class CustomviewActivity e
我正在尝试使用 ajax 实现带有上传百分比的标签。问题是xhr返回100%后,到readyState==4和status==200还需要17秒左右。 我正在使用 FormData() 对象发送图片
我正在使用 XmlHttpRequests 将图像上传到服务器,我想向用户显示这些上传的进度。 不幸的是,调用我的 onprogress-event 处理程序之间的间隔太大。通常,对于 500k 的图
进度条不更新。然而,它在任务完成时结束。 int totalSms = 12; int currentSms = 0; public class ProgressTask extends AsyncT
我正在使用 XmlHttpRequests 将图像上传到服务器,我想向用户显示这些上传的进度。 不幸的是,对我的 onprogress-event 处理程序的调用之间的间隔太大。对于 500k 的图像
我正在尝试使用 HTML5 制作一个带有进度表的文件 uploader 。这是我的代码: Test Progress Meter function submit
当发送带有 async = false 的 XMLHttpRequest 时,xhr.upload.onprogress 事件永远不会在文件上传时触发。 来源: var form = new Form
我有以下 AJAX 代码,脚本将文件正确上传到服务器(node express)。我面临的问题是 onProgress 仅在下载总字节时(因此在文件上传结束时)触发,而不是在其进度期间触发。 目前我无
Fine Uploader 的 onProgress() 回调在 Android 设备上不起作用。这是我的代码: onProgress: function(id, fileName, loaded,
我在获取在 chrome 上工作的音频标签的 onprogress 事件时遇到问题。它似乎适用于火狐。 http://www.scottandrew.com/pub/html5audioplayer/
您的浏览器如何决定触发 FileReader.onprogress 事件的频率?我在这个事件中做了一些处理,我认为它比我想要的更频繁地触发。我想要更大的 block 。有没有办法告诉它少开火? 示例代
我在通过 XHR 上传文件时订阅了 onProgress 事件。我的进度条是动画的(通过 jQuery)以提供更好的视觉美感。 onProgress 似乎触发得非常快,所以我想知道它实际触发的频率,以
除了永远不会触发 xhr.upload.onprogress 事件之外,以下代码中的所有内容都可以正常工作。 $(function(){ var xhr; $("#submit").c
我目前正在尝试构建一个 ajax 图像 uploader ,除了一个重要部分之外,我让它可以正常工作。 对于我上传的每个单独文件,我想更新该文件的进度条。目前它只更新最后一个文件的进度条。
如何确保在加载模型时定期更新加载进度,以便我可以构建加载图标。我已经跟踪了我能找到的每一个图例,但对于每个答案,onProgress 方法只会在加载完成后触发一次。 我的 typescript 加载器
我有一个 React 应用程序来播放来自后端的一些视频。为了播放视频,我集成了 npm 模块react-azure-mp 作为 Azure 媒体播放器的包装模块。根据 Azure 媒体播放器文档,有一
简短版: 我想得到 this与this一起工作: 长版: 我想创建一个 jQuery 扩展,它向 $.ajax 对象添加一个进度方法,并与 IE8 和 IE9 的 XDomainRequest 对象一
我正在尝试使用两个拇指搜索栏 我正在使用 This - PROJECT MainActivity.java public class MainActivity extends Activity {
您好,我在为场景加载纹理时生成加载消息时遇到了一些问题。 onProgress console.log 消息仅在纹理完全下载时触发,而不是在下载期间触发。 manager = new THREE.
问题 我有一个页面,用户可以在 FormData 和 XMLHttpRequest 的帮助下上传文件。上传文件工作正常。但是 upload.onprogress 仅在从 HTTP 连接上传时起作用。
我是一名优秀的程序员,十分优秀!