- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
friend 们,大家好,
我正在创建一个网站,我需要在主页中插入一张用动画扭曲的图像。为此,我得到了一个名为 Courtain.js 的库,需要我去理解它,而开发人员设法使其工作并作为 React 的组件向我发送了这段代码。
import React, { Component } from 'react';
import './App.css';
import image from './images/1.png';
import {Curtains} from 'curtainsjs';
const planeParams = {
vertexShaderID: "plane-vs", // our vertex shader ID
fragmentShaderID: "plane-fs", // our framgent shader ID
uniforms: {
time: {
name: "uTime", // uniform name that will be passed to our shaders
type: "1f", // this means our uniform is a float
value: 0,
},
}
};
class CurtainsPage extends React.Component {
constructor( props ) {
super(props);
this._planes = null;
}
componentDidMount() {
// if we got our curtains object, create the plane
this.props.curtains && this.createPlanes(this.props.curtains);
}
componentWillUpdate(nextProps, nextState) {
// if we haven't got our curtains object before but got it now, create the plane
if(!this.props.curtains && nextProps.curtains) {
this.createPlanes(nextProps.curtains);
}
}
componentWillUnmount() {
// remove the plane before unmounting component
if(this.props.curtains && this._planes) {
this.props.curtains.removePlane(this._planes);
this._planes = null;
}
}
createPlanes(curtains) {
// create our plane
if(curtains) {
this._planes = curtains.addPlane(this.planeElement, planeParams);
this._planes.onRender(function() {
this.uniforms.time.value++;
});
}
}
// register our plane element ref
registerPlaneElement(el) {
this.planeElement = el;
}
render() {
return (
<div
className="curtain"
ref={(el) => this.registerPlaneElement(el)}
>
<img src={image} alt={"image"}/>
</div>
);
}
}
class App extends Component {
constructor( props ) {
super(props);
this.state = {
curtains: null
};
}
componentDidMount() {
let curtains = new Curtains("canvas");
this.setState({ curtains: curtains });
}
render() {
let curtains = this.state.curtains;
console.log("start",curtains)
return (
<div className="App">
<div id="canvas" />
<CurtainsPage curtains={curtains}/>
</div>
);
}
}
export default App;
问题是我使用 Next JS 开发的网站并且该技术使用了 SSR,我认为这给我带来了问题。库函数甚至无法识别我发送的着色器。有人可以帮我弄这个吗?这是我在 Next JS 中的代码。
import { Fragment, Component } from "react";
import Nav from "../components/Nav";
import { motion } from "framer-motion";
import ArrowDownIcon from "@material-ui/icons/KeyboardArrowDown";
import "./index.scss";
import image from "./img/1.png";
import { Curtains } from "curtainsjs";
const planeParams = {
vertexShaderID: "plane-vs", // our vertex shader ID
fragmentShaderID: "plane-fs", // our framgent shader ID
uniforms: {
time: {
name: "uTime", // uniform name that will be passed to our shaders
type: "1f", // this means our uniform is a float
value: 0
}
}
};
class CurtainsPage extends Component {
constructor(props) {
super(props);
this._planes = null;
}
componentDidMount() {
// if we got our curtains object, create the plane
this.props.curtains && this.createPlanes(this.props.curtains);
}
componentWillUpdate(nextProps, nextState) {
// if we haven't got our curtains object before but got it now, create the plane
if (!this.props.curtains && nextProps.curtains) {
this.createPlanes(nextProps.curtains);
}
}
componentWillUnmount() {
// remove the plane before unmounting component
if (this.props.curtains && this._planes) {
this.props.curtains.removePlane(this._planes);
this._planes = null;
}
}
createPlanes(curtains) {
// create our plane
if (curtains) {
this._planes = curtains.addPlane(this.planeElement, planeParams);
this._planes.onRender(function() {
this.uniforms.time.value++;
});
}
}
// register our plane element ref
registerPlaneElement(el) {
this.planeElement = el;
}
render() {
return (
<div className="curtain" ref={el => this.registerPlaneElement(el)}>
<span>Hey</span>
<img src={image} alt={"image"} />
</div>
);
}
}
class Index extends Component {
constructor(props) {
super(props);
this.state = {
curtains: null
};
}
componentDidMount() {
let curtains = new Curtains("canvas");
this.setState({ curtains: curtains });
}
render() {
let curt = null;
if (typeof window !== "undefined") {
let curtains = this.state.curtains;
console.log("start", curtains);
curt = <CurtainsPage curtains={curtains} />;
}
return (
<Fragment>
<Nav />
<div id="homesection">
<div id="bigheader">
<div id="canvas" />
{curt}
</div>
<div className="sectionfooter">
<div className="flexcenterall">
<ArrowDownIcon className="marginbigright" />
<span className="fuentesecundaria normal">
Scroll down to continue
</span>
</div>
</div>
</div>
<div id="firstsection">
<div id="firstcontent">Hey</div>
<div className="sectionfooter">
<div className="flexcenterall">
<ArrowDownIcon className="marginbigright moradotext" />
<span className="fuentesecundaria normal negrotext big">
Where do you want to start?
</span>
</div>
</div>
</div>
<div id="secondsection">
<div>
<h2>MARKETING & COPYWRIGHTING</h2>
</div>
<div>Hola</div>
<div>Hola</div>
<div>Hola</div>
<div>Hola</div>
</div>
</Fragment>
);
}
}
export default Index;
图像出现但没有变形,我认为这是因为库没有正确接收参数或者是SSR错误。我收到错误,指出未指定顶点和着色器。
最佳答案
不要将着色器指定为 HTML ID 字符串,而是直接将它们作为字符串传递:
const vertexShader = `
precision mediump float;
// default mandatory variables
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
// our texture matrix uniform
// since no data-sampler attribute is specified on your <img /> tag
// the texture matrix use the default lib name: "uTextureMatrix0"
uniform mat4 uTextureMatrix0;
// custom variables
varying vec3 vVertexPosition;
varying vec2 vTextureCoord;
void main() {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
// do what you need to do in your vertex shader here...
// varyings
vTextureCoord = (uTextureMatrix0* vec4(aTextureCoord, 0.0, 1.0)).xy;
vVertexPosition = aVertexPosition;
}
`;
const fragmentShader = `
precision mediump float;
varying vec3 vVertexPosition;
varying vec2 vTextureCoord;
// since no data-sampler attribute is specified on your <img /> tag
// the sampler name use the default lib name: "uSampler0"
uniform sampler2D uSampler0;
void main() {
// do what you need to do in your fragment shader...
vec4 texture = texture2D(uSampler0, vTextureCoord);
// draw our texture
gl_FragColor = texture;
}
`;
const planeParams = {
vertexShader: vertexShader, // our vertex shader
fragmentShader: fragmentShader, // our framgent shader
uniforms: {
time: {
name: "uTime", // uniform name that will be passed to our shaders
type: "1f", // this means our uniform is a float
value: 0
}
}
};
这应该可以解决您的问题。
关于javascript - Next JS 与 Courttain.js 库未接收参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60420085/
这个问题已经有答案了: How to modify a public field of a field of a field… As in link.next.next.next(.next*n) n
我有一个保存链接的数组。每个链接都有一个名为 next 的公共(public)字段,它可以保存另一个链接,该链接可以保存更多链接等。当我想删除东西时我可以做 array[x].next = array
文档概述了在中间件中使用“await next()”的用例,导致中间件暂停并触发下游的下一个中间件,直到所有中间件都执行完毕,此时上游级联将开始并且中间件将完整执行。如果用户想要缩短级联,那么单独写“
我今天遇到了一个用例,我试图让我的 nextjs 应用程序在 android webview 中工作,不幸的是 android 不解析以 _next 开头的路径并且我的大部分块文件都在_next/st
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
next-with-apollo npm 库和 the approach shown in next.js docs 中选择的“next.js 中的 apollo-client”方法对比. next.
我尝试使用 next-auth 获取凭据身份验证,但我没有使用它的经验,无论我做什么,我都会收到以下消息:[next-auth][error][callback_credentials_jwt_err
更改语言时需要更改路线名称。例如,我有一条路线 /en/career但是当我改成捷克语时,我需要一条路线 /cs/kariera .基本上我需要本地化 URL。现在,当我在 /en/career 上时
更好/优雅的方法是什么? jQuery(this).find('title').next().next().next().eq(0).text(); //THIS WORKS 我尝试使用 jQuery
我只是对 node 感到好奇。 node.next 和 node.next。到目前为止,我们已经了解到节点有两个部分,其中存储数据和下一个节点的地址(node.next),然后是 node.next.
好的,我正在尝试单独隐藏这组信息。 这有效: $(".arrow").click(function() { $(this).next().next().slideToggle(); }); Mo
我开发了一个 Web 应用程序,它使用 Nextjs 应用程序作为前端和一个 Python (Django) API 服务器作为后端。我的大多数前端页面都有对后端服务器的 API 调用(在 Compo
如果我没有通过身份验证,我正在尝试使用NextJS中间件保护一些路由,我正在使用Next-auth进行身份验证,从文档中看,这就是MIDDLEWAR.TS文件应该是什么样子。Rn的问题是,即使当我通过
我正在使用 nextJs,需要添加对 less 和 css 的支持。我想要一个项目同时拥有 next-css 和 next-less 。但它一次接受一个。这是我正在使用的 const withCSS
我正在构建下一个项目的 typescript 。如果我将此配置文件保留为 next.config.js , 我在 tsconfig.json 收到警告说“找不到next.config.ts”。所以 t
我有一个自定义登录网址/ View /模板。我对页面使用 @login_required 装饰器(让 称为 my_page) 需要登录。试图访问 my_site.com/my_page 正确调用 my
下面的代码工作正常: class String def foo next! end end puts 'hh'.foo # hi 这个也很好用: class String d
我在我的Next.js应用程序中使用Next-auth进行身份验证。成功登录后,我立即被重定向到登录页面,表明该会话已变为未经身份验证。。相关代码片段:。_app.tsx:。Layout.tsx:。L
我想在 nextjs 中创建动态页面以匹配以下路由 users/[user]/[dashboard]。我的文件结构 pages/ users/ -[user].js // will
我直接按照官网的步骤操作: https://nextjs.org/docs/ 第一步。 npm install --save next react react-dom 步骤 2. 将脚本添加到 pac
我是一名优秀的程序员,十分优秀!