抱歉我写标题时的英文不好,我已经尽力了。
直播站点:http://tt.fbcwinterretreat.org/ http://tt.fbcwinterretreat.org/请注意,为了更好地了解发生的情况,我建议您降低窗口高度。
问题是:如果您一直查看页面,轮播会顺利进行,但如果您切换到另一个浏览器选项卡,等待几秒钟,然后再切换回来,您会看到轮播发生移位。您在其他浏览器选项卡上停留的时间越长,它的位移就越多。
看来问题出在这个函数上:
function getRelativeClientRect(el) {
var rect = el.getBoundingClientRect(),
parentRect = el.offsetParent.getBoundingClientRect();
return {
bottom: parentRect.bottom - rect.bottom,
height: rect.height,
left: rect.left - parentRect.left,
right: parentRect.right - rect.right,
top: rect.top - parentRect.top,
width: rect.width
};
}
我从这个问题中得到的:如何获取绝对定位元素的左/右/上/下的实际值? https://stackoverflow.com/questions/23891892/how-do-i-get-the-actual-values-for-left-right-top-bottom-of-an-absolutely-positi.
以下是我网站的HTML和代码:
HTML:
<div class='marquee-container'>
<div class="image-container">
<div class="image" style="background-image:url('images/1.jpg')"></div>
<div class="image" style="background-image:url('images/2.jpg')"></div>
<div class="image" style="background-image:url('images/3.jpg')"></div>
<div class="image" style="background-image:url('images/4.jpg')"></div>
<div class="image" style="background-image:url('images/5.jpg')"></div>
</div>
</div>
CSS:
.marquee-container{position:relative;overflow:hidden}
.image-container{position:absolute;transition:all 1s ease; display: -webkit-box;display: -moz-box;display: -ms-flexbox;display: -webkit-flex;display: flex;}
.image{float:left;background-size:cover;cursor:pointer}
JS:有两个相关的JS脚本,第一个位于关闭body标签之前,我用它来使图像自动适应屏幕的高度
<script>
(function(){
var width, height = true;
function initHeader() {
headerHeight = document.getElementById('rt-header')? document.getElementById('rt-header').getHeight():0;
width = window.innerWidth;
height = window.innerHeight - headerHeight;
largeHeader = document.getElementById('rt-topfullwidth');
largeHeader.style.height = height+'px';
j('.marquee-container').height(height);
j('.marquee-container .image').height(height);
}
// Main
initHeader();
})();
</script>
第二个位于http://tt.fbcwinterretreat.org/templates/rt_chimera/js/custom.js http://tt.fbcwinterretreat.org/templates/rt_chimera/js/custom.js,我用它来实现轮播效果。我知道它的可读性很低,所以我添加了一些注释。