简体   繁体   English

背景附件:固定+背景尺寸:在iPad上覆盖?

[英]background-attachment: fixed + background-size: cover on Ipad?

I have some block with height 100%, and which scrolles down by single mouse wheel (I do it with mousewheel.js). 我有一些高度为100%的块,并且可以通过单个鼠标滚轮向下滚动(我使用mousewheel.js做到了)。 In that block I have 2 other blocks with height and width 100%, and with background images which changes with fade effect. 在那个块中,我还有另外两个块,其高度和宽度为100%,并且背景图像随着淡入淡出效果而变化。 I set background-size: cover and background-attachment: fixed for this blocks. 我设置了background-size: coverbackground-attachment: fixed为此块background-attachment: fixed的。 Its working fine on desktop browsers. 它可以在桌面浏览器上正常工作。 But on IPad I have some issues: 但是在iPad上,我有一些问题:

.first-block {
background-size: cover;
background-attachment: fixed;
position: absolute;
-webkit-transition: opacity 2s ease-in;
transition: opacity 2s ease-in;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100%;
width: 100%;
visibility: hidden;
opacity: 0;
top: 0;
}
  1. fixed and cover together dont work, images is too zoomed.. I decided to set background-attachment: scroll and emulate background-attachment: fixed with jQuery adding this code fixedcover在一起不起作用,图像过大..我决定设置background-attachment: scroll并模拟background-attachment: fixed使用jQuery添加此代码进行background-attachment: fixed

     $(window).scroll(function() { var scrolledY = $(window).scrollTop(); $('.first-block').css('background-position', 'center ' + ((scrolledY)) + 'px'); }); 

Its working fine, but on Ipad and Safari (Mac OS) its work too slow.. Its almost crash browser.. 它的工作正常,但是在Ipad和Safari(Mac OS)上,它的工作速度太慢了。它的浏览器几乎崩溃了。

When I change orientation of display in Ipad - background dont reconstructed for each orientation. 当我在Ipad中更改显示方向时-不要为每个方向重建背景。 Its display img size only first orientation. 其显示img大小仅是第一个方向。

I have read many many similar questions here, but I cant find the better solution for me. 我在这里阅读了许多类似的问题,但是我找不到适合我的更好的解决方案。 Please see JsFiddle demos. 请参阅JsFiddle演示。

DEMO with FIXED 固定演示

DEMO with emulating FIXED with jQuery 用jQuery模拟FIXED的演示

Thanks for any help. 谢谢你的帮助。

I'm not exactly an expert when it comes to understanding many scripts, but what I can tell you will pretty much solve your issue entirely. 在理解许多脚本方面,我并不是专家,但是我可以告诉您的内容将完全解决您的问题。 When you use scripts such as mousewheel.js, you're going to find out that handheld devices and tablets will react quite a bit differently than desktop browsers would. 当您使用诸如mousewheel.js之类的脚本时,您将发现手持设备和平板电脑的反应与台式机浏览器的反应将有很大不同。

As far as the lag you're experiencing, that's probably due to the limitation of the device its on. 就您遇到的延迟而言,这可能是由于设备开启的限制所致。 I'm sure that if you were to try it on other tablets, you'd find similar results to this. 我敢肯定,如果您要在其他平板电脑上尝试一下,将会发现与此类似的结果。 Your best solution is optimizing your website using media queries so you can ensure that although most users will have the experience you're intending, tablet users can still access needed information and the essential site functionality. 最好的解决方案是使用媒体查询来优化您的网站,以便您可以确保尽管大多数用户都会有您想要的体验,但平板电脑用户仍然可以访问所需的信息和基本的网站功能。

Things like: 像:

@media (min-width: 700px) and (orientation: landscape) { ... }

and: 和:

@media (min-width: 700px) { ... }

will let you code CSS specific to those conditions in CSS. 将允许您编写特定于CSS中这些条件的CSS。 You can find a resource here: 您可以在此处找到资源:

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Media_queries

I also suggest that if you're looking to keep what you wanted, then I'd take a look into experimenting with other JS files that do the same thing. 我还建议,如果您希望保留想要的内容,那么我将尝试使用其他具有相同功能的JS文件进行试验。

Sorry if what I provided doesn't give you the exact solution you need. 抱歉,如果我提供的内容不能为您提供所需的确切解决方案。

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

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