我仍然是一个学习开发人员,我不确定问题出在哪里,但我的视差图像似乎根本无法加载到Google Chrome上。火狐、IE和Safari似乎运行得无懈可击。我已经了解到,由于Chrome中的一个小故障,它可能与fixed属性有关,但我不确定我的下一步是什么。
所以我在我的许多页面上都有这个当前的英雄设置:
<section class="hero-fullscreen parallax">
<div class="background-image">
<img src="img/backgrounds/encounter.png" alt="img">
</div>
</section>
下面是我的CSS:
.hero-fullscreen {
position: relative;
width: 100%;
height: 100%;
background-color: #0f1112;
}
.parallax {
position: relative;
overflow: hidden
}
.parallax .container {
position: relative;
z-index: 2;
}
.parallax > .background-image,
.parallax .slides li > .background-image {
height: 100vh;
top: -50vh;
transition: opacity 0.9s ease;
-webkit-transform-style: preserve-3d;
}
.parallax:first-child .slides li > .background-image,
.parallax:first-child .background-image,
.hero-fullscreen.parallax .background-image {
top: 0;
}
.main-container > a:first-child + .parallax .background-image {
top: 0;
}
@media all and (max-width: 1024px) {
.parallax > .background-image,
.parallax .slides li > .background-image {
top: 0 !important;
transform: none !important;
-webkit-transform: none !important;
height: 100%;
}
}
/* Background Image */
.background-image {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-size: cover !important;
background-position: 50% 50% !important;
z-index: 0;
opacity: 0;
background: #1c1c1c;
transition: opacity .3s;
-webkit-transition: opacity .3s;
-moz-transition: opacity .3s;
}
.background-image img {
display: none
}
section {
position: relative;
}
使用我的JS:
parallaxVossen();
var isOpera, isFirefox, isSafari, isIE, isEdge, isChrome, isBlink, isMob;
isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
isFirefox = typeof InstallTrigger !== 'undefined';
isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
isIE = navigator.userAgent.indexOf("MSIE ");
isEdge = !isIE && !!window.StyleMedia;
isChrome = !!window.chrome && !!window.chrome.webstore;
isBlink = (isChrome || isOpera) && !!window.CSS;
isMob = (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
if (isChrome || isFirefox || isSafari) {
if ($(window).width() > 992) {
$('.parallax').vossenParallax();
};
$(window).scroll(function () {
function parallaxHero() {
var scrolled = $(window).scrollTop();
if ($(window).width() > 992) {
$('.map-parallax').css('top', -(scrolled * 0.4) + 'px');
$(".slide").css({transform: 'translate3d(0px, ' + (scrolled * 0.4) + 'px, 0px)'});
}
}
parallaxHero();
});
}
$(window).load(function () {
$('.parallax-bg img').animate({opacity : 1}, 1000);
$('.white-until-load').css({color : "#191a1c"});
});
就像我说的,它似乎可以在除Google Chrome之外的所有浏览器上运行。
自己试试:http://www.gracechurch.tv
有什么想法吗?
发布于 2018-06-12 02:56:40
目前,我在网上找到了两个有效的修复方法。
您可以将以下属性添加到包含固定附件背景图像的元素中。
yourdiv {
position:relative;
background-image:url(your_image);
background-size:cover;
background-position:center;
background-attachment:fixed;
transform: translate3d(0,0,0);
-webkit-transform: translate3d(0,0,0);
}
也可以将背景固定图像的元素的位置更改为静态。
yourdiv {
position:static;
background-image:url(your_image);
background-size:cover;
background-position:center;
background-attachment:fixed;
}
希望这能暂时帮上忙。
发布于 2018-06-08 05:37:54
这是Chromes从66更新到67的一个问题。查看您正在运行的Chrome版本。如果是67,那就是你的问题了…或者我应该说,谷歌的问题。我在66版本的其他CPU上测试了我的站点,没有任何问题。
https://stackoverflow.com/questions/50748944
复制相似问题