- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
基本上遵循基于 ES6 和 TweenMax 的代码,它工作正常,但我想修复滚动事件,例如鼠标向上滚动 slider 动画(更改)从底部到顶部和鼠标再次向下滚动 slider 动画从上到下。
我还想根据右中心导航更改点击时的 slider !
感谢高级!
class Slider {
constructor() {
this.bindAll();
this.el = document.querySelector(".js-slider");
this.inner = this.el.querySelector(".js-slider__inner");
this.slides = [...this.el.querySelectorAll(".js-slide")];
this.bullets = [...this.el.querySelectorAll(".js-slider-bullet")];
this.renderer = null;
this.scene = null;
this.clock = null;
this.camera = null;
this.images = [
"https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/bg1.jpg",
"https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/bg2.jpg",
"https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/bg3.jpg"
];
this.data = {
current: 0,
next: 1,
total: this.images.length - 1,
delta: 0
};
this.state = {
animating: false,
text: false,
initial: true
};
this.textures = null;
this.init();
}
bindAll() {
["render", "nextSlide"].forEach(fn => (this[fn] = this[fn].bind(this)));
}
setStyles() {
this.slides.forEach((slide, index) => {
if (index === 0) return;
TweenMax.set(slide, {
autoAlpha: 0
});
});
this.bullets.forEach((bullet, index) => {
if (index === 0) return;
const txt = bullet.querySelector(".js-slider-bullet__text");
const line = bullet.querySelector(".js-slider-bullet__line");
TweenMax.set(txt, {
alpha: 0.25
});
TweenMax.set(line, {
scaleX: 0,
transformOrigin: "left"
});
});
}
cameraSetup() {
this.camera = new THREE.OrthographicCamera(
this.el.offsetWidth / -2,
this.el.offsetWidth / 2,
this.el.offsetHeight / 2,
this.el.offsetHeight / -2,
1,
1000
);
this.camera.lookAt(this.scene.position);
this.camera.position.z = 1;
}
setup() {
this.scene = new THREE.Scene();
this.clock = new THREE.Clock(true);
this.renderer = new THREE.WebGLRenderer({
alpha: true
});
this.renderer.setPixelRatio(window.devicePixelRatio);
this.renderer.setSize(this.el.offsetWidth, this.el.offsetHeight);
this.inner.appendChild(this.renderer.domElement);
}
loadTextures() {
const loader = new THREE.TextureLoader();
loader.crossOrigin = "";
this.textures = [];
this.images.forEach(image => {
const texture = loader.load(image + "?v=" + Date.now(), this.render);
texture.minFilter = THREE.LinearFilter;
this.textures.push(texture);
});
this.disp = loader.load(
"https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/rock-_disp.png",
this.render
);
this.disp.magFilter = this.disp.minFilter = THREE.LinearFilter;
this.disp.wrapS = this.disp.wrapT = THREE.RepeatWrapping;
}
createMesh() {
this.mat = new THREE.ShaderMaterial({
uniforms: {
dispPower: {
type: "f",
value: 0.0
},
intensity: {
type: "f",
value: 0.5
},
texture1: {
type: "t",
value: this.textures[0]
},
texture2: {
type: "t",
value: this.textures[1]
},
disp: {
type: "t",
value: this.disp
}
},
transparent: true,
vertexShader: document.querySelector("#vertexShader").textContent,
fragmentShader: document.querySelector("#fragmentShader").textContent
});
const geometry = new THREE.PlaneBufferGeometry(
this.el.offsetWidth,
this.el.offsetHeight,
1
);
const mesh = new THREE.Mesh(geometry, this.mat);
this.scene.add(mesh);
}
transitionNext() {
TweenMax.to(this.mat.uniforms.dispPower, 2.5, {
value: 1,
ease: Expo.easeInOut,
onUpdate: this.render,
onComplete: () => {
this.mat.uniforms.dispPower.value = 0.0;
this.changeTexture();
this.render.bind(this);
this.state.animating = false;
}
});
const current = this.slides[this.data.current];
const next = this.slides[this.data.next];
const currentImages = current.querySelectorAll(".js-slide__img");
const nextImages = next.querySelectorAll(".js-slide__img");
const currentText = current.querySelectorAll(".js-slider__text-line div");
const nextText = next.querySelectorAll(".js-slider__text-line div");
const currentBullet = this.bullets[this.data.current];
const nextBullet = this.bullets[this.data.next];
const currentBulletTxt = currentBullet.querySelectorAll(
".js-slider-bullet__text"
);
const nextBulletTxt = nextBullet.querySelectorAll(
".js-slider-bullet__text"
);
const currentBulletLine = currentBullet.querySelectorAll(
".js-slider-bullet__line"
);
const nextBulletLine = nextBullet.querySelectorAll(
".js-slider-bullet__line"
);
const tl = new TimelineMax({
paused: true
});
if (this.state.initial) {
TweenMax.to(".js-scroll", 1.5, {
yPercent: 100,
alpha: 0,
ease: Power4.easeInOut
});
this.state.initial = false;
}
tl
.staggerFromTo(
currentImages,
1.5, {
yPercent: 0,
scale: 1
}, {
yPercent: -185,
scaleY: 1.5,
ease: Expo.easeInOut
},
0.075
)
.to(
currentBulletTxt,
1.5, {
alpha: 0.25,
ease: Linear.easeNone
},
0
)
.set(
currentBulletLine, {
transformOrigin: "right"
},
0
)
.to(
currentBulletLine,
1.5, {
scaleX: 0,
ease: Expo.easeInOut
},
0
);
if (currentText) {
tl.fromTo(
currentText,
2, {
yPercent: 0
}, {
yPercent: -100,
ease: Power4.easeInOut
},
0
);
}
tl
.set(current, {
autoAlpha: 0
})
.set(
next, {
autoAlpha: 1
},
1
);
if (nextText) {
tl.fromTo(
nextText,
2, {
yPercent: 100
}, {
yPercent: 0,
ease: Power4.easeOut
},
1.5
);
}
tl
.staggerFromTo(
nextImages,
1.5, {
yPercent: 150,
scaleY: 1.5
}, {
yPercent: 0,
scaleY: 1,
ease: Expo.easeInOut
},
0.075,
1
)
.to(
nextBulletTxt,
1.5, {
alpha: 1,
ease: Linear.easeNone
},
1
)
.set(
nextBulletLine, {
transformOrigin: "left"
},
1
)
.to(
nextBulletLine,
1.5, {
scaleX: 1,
ease: Expo.easeInOut
},
1
);
tl.play();
}
prevSlide() {}
nextSlide() {
if (this.state.animating) return;
this.state.animating = true;
this.transitionNext();
this.data.current =
this.data.current === this.data.total ? 0 : this.data.current + 1;
this.data.next =
this.data.current === this.data.total ? 0 : this.data.current + 1;
}
changeTexture() {
this.mat.uniforms.texture1.value = this.textures[this.data.current];
this.mat.uniforms.texture2.value = this.textures[this.data.next];
}
listeners() {
window.addEventListener("wheel", this.nextSlide, {
passive: true
});
}
render() {
this.renderer.render(this.scene, this.camera);
}
init() {
this.setup();
this.cameraSetup();
this.loadTextures();
this.createMesh();
this.setStyles();
this.render();
this.listeners();
}
}
// Toggle active link
const links = document.querySelectorAll(".js-nav a");
links.forEach(link => {
link.addEventListener("click", e => {
e.preventDefault();
links.forEach(other => other.classList.remove("is-active"));
link.classList.add("is-active");
});
});
// Init classes
const slider = new Slider();
@font-face {
font-family: 'font';
src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/OakesGrotesk-Semi-Bold.woff2") format("woff2");
src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/OakesGrotesk-Semi-Bold.woff") format("woff");
font-weight: 600;
font-style: normal;
}
@font-face {
font-family: 'font-2';
src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/MaisonNeue-Book.woff2") format("woff2");
src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/MaisonNeue-Book.woff") format("woff");
font-weight: normal;
font-style: normal;
}
html {
font-size: 16px;
}
html,
body {
height: 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
background-color: #111;
font-family: 'font';
overflow: hidden;
}
a {
color: #fff;
text-decoration: none;
}
.scroll {
position: absolute;
bottom: 2rem;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
color: rgba(255, 255, 255, 0.5);
font-family: 'font-2';
font-size: calc(0.5rem + 0.35vw);
z-index: 10;
}
.logo {
position: absolute;
top: 2rem;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
padding: 0;
margin: 0;
z-index: 10;
}
.logo img {
display: block;
height: 1rem;
width: auto;
}
ul,
li {
list-style: none;
padding: 0;
margin: 0;
}
.nav {
position: absolute;
top: 2rem;
z-index: 10;
}
.nav--left {
left: 1rem;
}
.nav--right {
right: 1rem;
}
.nav ul {
display: flex;
align-items: center;
height: 1rem;
}
.nav li {
display: block;
margin: 0 1rem;
padding: 0;
}
.nav a {
position: relative;
display: flex;
align-items: center;
font-size: calc(0.5rem + 0.35vw);
font-family: 'font-2';
}
.nav a span {
position: relative;
}
.nav a span:before {
content: '';
position: absolute;
left: 0;
bottom: -0.35rem;
width: 100%;
height: 1px;
background-color: rgba(255, 255, 255, 0.25);
transition: -webkit-transform .75s ease;
transition: transform .75s ease;
transition: transform .75s ease, -webkit-transform .75s ease;
-webkit-transform-origin: right;
transform-origin: right;
-webkit-transform: scaleX(0);
transform: scaleX(0);
}
.nav a:hover span:before,
.nav a.is-active span:before {
-webkit-transform: scaleX(1);
transform: scaleX(1);
-webkit-transform-origin: left;
transform-origin: left;
}
.vert-text {
position: absolute;
bottom: 2rem;
right: 2rem;
width: 15rem;
display: flex;
align-items: center;
z-index: 10;
}
.vert-text span {
display: block;
color: #fff;
text-transform: uppercase;
line-height: 1.1;
-webkit-transform: rotate(-90deg) translateY(15rem);
transform: rotate(-90deg) translateY(15rem);
-webkit-transform-origin: bottom left;
transform-origin: bottom left;
font-size: 1.35rem;
}
.cart-total {
display: block;
height: 2rem;
width: 2rem;
background-color: rgba(255, 255, 255, 0.25);
border-radius: 50%;
text-align: center;
line-height: 2rem;
margin-left: 1rem;
}
.slider {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.slider__text {
position: absolute;
bottom: calc(2rem + 3vw);
left: calc(2rem + 3vw);
z-index: 10;
font-size: calc(1rem + 4vw);
text-transform: uppercase;
-webkit-transform-origin: top;
transform-origin: top;
line-height: 1.075;
color: #fff;
}
.slider__text-line {
overflow: hidden;
}
.slider__inner {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.slider__nav {
position: absolute;
top: 50%;
right: 0;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
z-index: 10;
}
.slider-bullet {
display: flex;
align-items: center;
padding: 1rem 0;
}
.slider-bullet__text {
color: #fff;
font-size: 0.65rem;
margin-right: 1rem;
}
.slider-bullet__line {
background-color: #fff;
height: 1px;
width: 1rem;
}
.slider canvas {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.slide {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
overflow: hidden;
}
.slide__content {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.slide__img {
position: relative;
width: 25vw;
height: 70vh;
padding: 0;
margin: 0;
min-width: 12.5rem;
-webkit-transform-origin: top;
transform-origin: top;
}
.slide__img:first-child {
top: -1.5rem;
}
.slide__img:last-child {
bottom: -1.5rem;
}
.slide__img img {
display: block;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
-o-object-fit: cover;
object-fit: cover;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TweenMax.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/97/three.min.js"></script>
<nav class="nav nav--left js-nav">
<ul>
<li>
<a href="#"><span>Mens</span></a>
</li>
<li>
<a href="#"><span>Womens</span></a>
</li>
<li>
<a href="#" class="is-active"><span>Collections</span></a>
</li>
</ul>
</nav>
<figure class="logo">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/logo_copy_copy.svg">
</figure>
<nav class="nav nav--right">
<ul>
<li>
<a href="https://twitter.com/Jesper_Landberg?lang=en" target="_blank"><span>Say hi</span></a>
</li>
<li>
<a href="#">
<span>Cart</span>
<div class="cart-total">0</div>
</a>
</li>
</ul>
</nav>
<div class="slider js-slider">
<div class="slider__inner js-slider__inner"></div>
<div class="slide js-slide">
<div class="slide__content">
<figure class="slide__img js-slide__img">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/photo1.jpg">
</figure>
<figure class="slide__img js-slide__img">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/photo2.jpg">
</figure>
</div>
<div class="slider__text js-slider__text">
<div class="slider__text-line js-slider__text-line">
<div>Black is</div>
</div>
<div class="slider__text-line js-slider__text-line">
<div>timeless. Black is</div>
</div>
<div class="slider__text-line js-slider__text-line">
<div>the colour of</div>
</div>
<div class="slider__text-line js-slider__text-line">
<div>Eternity.</div>
</div>
</div>
</div>
<div class="slide js-slide">
<div class="slide__content">
<figure class="slide__img js-slide__img">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/photo3.jpg">
</figure>
<figure class="slide__img js-slide__img">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/photo4.jpg">
</figure>
</div>
</div>
<div class="slide js-slide">
<div class="slide__content">
<figure class="slide__img js-slide__img">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/photo5.jpg">
</figure>
<figure class="slide__img js-slide__img">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/58281/photo6.jpg">
</figure>
</div>
</div>
<nav class="slider__nav js-slider__nav">
<div class="slider-bullet js-slider-bullet">
<span class="slider-bullet__text js-slider-bullet__text">01</span>
<span class="slider-bullet__line js-slider-bullet__line"></span>
</div>
<div class="slider-bullet js-slider-bullet">
<span class="slider-bullet__text js-slider-bullet__text">02</span>
<span class="slider-bullet__line js-slider-bullet__line"></span>
</div>
<div class="slider-bullet js-slider-bullet">
<span class="slider-bullet__text js-slider-bullet__text">03</span>
<span class="slider-bullet__line js-slider-bullet__line"></span>
</div>
</nav>
<div class="scroll js-scroll">Scroll</div>
</div>
<div class="vert-text">
<span>
Wings+Horns<br>
X Kyoto Black
</span>
</div>
<script id="vertexShader" type="x-shader/x-vertex">
varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
varying vec2 vUv; uniform sampler2D texture1; uniform sampler2D texture2; uniform sampler2D disp; uniform float dispPower; uniform float intensity; void main() { vec2 uv = vUv; vec4 disp = texture2D(disp, uv); vec2 dispVec = vec2(disp.x, disp.y); vec2
distPos1 = uv + (dispVec * intensity * dispPower); vec2 distPos2 = uv + (dispVec * -(intensity * (1.0 - dispPower))); vec4 _texture1 = texture2D(texture1, distPos1); vec4 _texture2 = texture2D(texture2, distPos2); gl_FragColor = mix(_texture1, _texture2,
dispPower); }
</script>
最佳答案
您已经在 nextSlide 函数中捕获了 wheel
事件。您现在需要做的就是阅读它的 event.deltaY
value确定滚动是向上还是向下。这是一些伪代码:
var prevY = 0;
var newY = 0;
nextSlide(event) {
newY = event.deltaY;
if(newY > prevY){
slideDown();
}else if(newY < prevY) {
slideUp();
}
// Store deltaY into prevY for comparison on next scroll
prevY = event.deltaY;
}
关于javascript - 在鼠标滚动上动画 TweenMax 幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53202120/
我制作了一个 jquery 幻灯片,代码如下: HTML previous Next CSS #slideshow { width: 700px; h
我正在用 Javascript 制作幻灯片,带有播放/暂停和下一个/上一个按钮。我已经设法使用播放/暂停按钮进行幻灯片放映,但现在我想向其中添加“下一个”和“上一个”按钮。有人可以帮我吗?我该怎么做?
我是 Java 脚本新手,我正在尝试为我的页面构建幻灯片。这是我的 html 代码: 和我的 Js 脚本: var numar_ima
我可以修改此现有代码以自动滚动列表项以显示内容吗? 抱歉,:ul li a {} 链接。 也许使用“间隔”方法? $(document).ready(function(){ $('ul.tab
我正在尝试熟悉 jQuery 工具 - Flowplayer 中的幻灯片 ( http://flowplayer.org/tools/tabs/slideshow.html )。有没有人提示我如何选择
这个问题在这里已经有了答案: Return to 1st image on slideshow (2 个答案) 关闭 3 年前。 有谁知道如何在此幻灯片中添加另一个按钮,使用户在幻灯片放映期间的任何
我知道这听起来很傻,我可以使用一些现成的解决方案,但我真的很想构建自己的简单图像幻灯片。我在 Silverlight/WPF 中进行应用程序开发已经有一段时间了,但无论出于何种原因,我都无法解决这个问
我正在尝试设置此幻灯片脚本,以便显示的第一张图片是随机的(每次我们访问该网站时,我都需要第一张图片是不同/随机的幻灯片),其余图片可以显示在正确的顺序,没关系。 我正在使用 Jon Raasch 的简
我们的 flexslider 上最后一张图片的一小部分在幻灯片加载后立即闪烁整个页面。第一个图像设置为可见,所有其他图像设置为隐藏。插件设置为在页面加载后运行。我认为可能是页面上的其他原因导致了此问题
我有一个自动幻灯片放映效果很好。但是,我希望能够改变某些幻灯片的速度这是代码: var slideIndex = 0; showSlides(); function showSlides() {
如有任何帮助,我们将不胜感激! 我正在尝试从以下位置实现脚本: www.switchonthecode.com/tutorials/jquery-creating-a-slideshow 但我希望它连
我用 javascript 创建了以下幻灯片。但是由于某种原因,在第一张图片滑过时,第一张图片刚好移开,而第二张图片进行了“滑动”。任何帮助,将不胜感激。我添加了注释以帮助提高代码的可读性。
我正在使用在以下网站在线找到的带缩略图的图像幻灯片。有谁知道我将如何更改此幻灯片,以便将缩略图列在幻灯片的右侧,而不是列在其下方。如果您转到下面的链接,然后单击查看演示,您可以看到我的幻灯片目前是如何
我希望在悬停链接时有过渡效果。我希望在链接后顺利显示文本。 这就是我目前所拥有的: p { border-radius: 1em; padding: 0.5em; backgr
我喜欢jQuery的幻灯片效果,当你move a cursor on some of products 我正在尝试使用类似的功能实现相同的效果,但有一个区别 - 当我在框上移动光标时,我想显示带有信息
我正在尝试创建自己的幻灯片。以下代码从一张图像淡入另一张图像。我想从 img1.jpg 循环到 img4.jpg,但我不确定如何在每次更改后暂停。 i++;
jquery 中的代码是什么,可以让幻灯片放映在最后一张照片上单击“下一步”后显示第一张照片。我知道我只需要写一次文档准备好,但我还没有这样做,但我会的。这是我的代码
如何添加指向这些图像的链接。我尝试过多种幻灯片放映方式,但发现当我添加链接时,它开始不显示所有其他图像。在我下面的代码中,我将链接注释掉了。如果我删除链接,图像显示正常。 我已经重复了两次图像只是为了
我似乎无法制作完全可用的 CSS 幻灯片,其中幻灯片的显示时间各不相同。我需要使用多个关键帧还是有其他方法可以做到这一点?如果是,将不胜感激 :^) 最佳答案 您可以使用单个关键帧设置和 CSS3 的
我用 HTML/CSS/JS 制作了这个小幻灯片。 大部分都在工作,但有一件事我想不通。 当自动滑动打开时,如何使每个图像上方的文本适合 img 本身? 现在它只在我手动点击时显示每个 img 的正确
我是一名优秀的程序员,十分优秀!