简体   繁体   English

背景图像水平视差

[英]Background Image Horizontal Parallax

So I am working on building a jQuery swipe feature mainly designed for mobile devices and am entering an area I've never entered before with a parallax background of sorts. 因此,我正在构建主要为移动设备设计的jQuery滑动功能,并且正在以某种视差背景进入我从未进入过的区域。 I am trying to keep the background image height to the size of the screen which I can achieve with the cover property 我正在尝试将背景图像的高度保持为屏幕的大小,这可以通过cover属性实现

background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;

however this doesn't get me the parallax effect I want for the width, I suppose the best way to understand what I am trying to do would be something like what is talked about in this question 但这并不能使我获得想要的宽度视差效果,我想理解我想要做的最好方法就是像在这个问题中讨论的那样

Horizontal scrolling with parallax background for ios iOS视差背景水平滚动

but with javascript/jquery,css & html. 但使用javascript / jquery,css和html。 I am continuing to work on a solution but exactly what I have so far can be see at: 我正在继续研究解决方案,但是到目前为止,我可以确切地看到:

http://2rivers.ml/confused http://2rivers.ml/confused

Any help on this would be greatly appreciated, this whole Parallax thing is new to me, I am not asking for someone to write the code for me but I am completely lost on how to go about achieving this and after dozens of Google searches I am not much closer than I was. 在这方面的任何帮助将不胜感激,这对我来说是全新的,我并不是要有人为我编写代码,但是我完全迷失了如何实现这一目标,在经过数十次Google搜索之后,我是距离我不远。

So this is a fairly straight forward thing to code yourself in javascript. 因此,用javascript编写代码是一件相当简单的事情。 This is a wikipedia article outlining the basic idea. 是Wikipedia文章,概述了基本概念。

Essentially you would set a handler on the scroll bar and whenever the page is scrolled update the position of the background layer (this might be by changing the position of an entire div or modifying the background-position CSS property) 本质上,您将在滚动条上设置一个处理程序,并且每当滚动页面时都会更新背景层的位置(这可能是通过更改整个div的位置或修改background-position CSS属性)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM