1

所以我在我的网站上使用 BackStretch jQuery 插件,到目前为止它运行良好。我看到的唯一问题是,在移动垂直屏幕上,当我开始向下滚动时,底部会出现一个空白白条 - 就在顶部 url 和底部浏览器菜单缩小/消失之后。当顶部和底部浏览器栏消失时,body 标记中的背景似乎没有记录它需要调整大小。关于如何解决这个问题的任何想法?我正在使用 Boostrap 3.0,并且在垂直滚动条上出现了一些白条问题,但我能够使用 overflow-x:hidden 解决这个问题。任何想法将不胜感激。该网站位于http://ivynursery.jacobbuller.com - 您可以在关于http://ivynursery.jacobbuller.com/about.php和联系方式上查看问题http://ivynursery.jacobbuller.com/contact.php页面。

这是我为 body 和 container div 设置的 css:

html,
body {
height: 100%;
position: relative;
}
body {
overflow-x: hidden;
/* Removes right space for browser scrollbar on mobile */
}
.container {
 margin-right: 15px;
 /* Adjust content to make up for hidden x-overflow 15px on mobile */
 }
 @media (min-width: 768px) {
 .container {
margin-right: auto;
/* Adjust content to middle for non-mobile */
}
}
4

1 回答 1

0

我尝试为 JS 中的 BackStretch 框和图像添加高度,例如 120 像素(大多数导航栏小于 60 像素)。

...:this.$root.height():this.$root.innerHeight(),g=g+120,...

但是当然,当您向下滚动时,您将获得其他内框高度,向下滚动后导航栏消失并且窗口变得更高,而不是我在 css/less 中冻结框更改

    .backstretch.freeze{
&,img{
        -webkit-transition: height 5000s ease-out, width 5000s ease-out, left 5000s ease-out, top 5000s ease-out;
        -o-transition: height 5000s ease-out, width 5000s ease-out left 5000s ease-out, top 5000s ease-out;
        transition: height 5000s ease-out, width 5000s ease-out left 5000s ease-out, top 5000s ease-out;
    }
}
 //hide empty space after navbar hide 
.backstretch{
    img{
        top:-60px;
    }
}

但是我遇到了下一个问题-更改屏幕旋转后,我得到了冻结图像bg。所以我需要一个 JS 函数。让我们在调整宽度时放置“冻结”类。但是当我们调整高度时 - 这意味着在移动设备上向下滚动时导航栏会跳跃。

var isMobile = false; //initiate as false
isMobile = window.matchMedia("only screen and (max-width: 767px)");
if (isMobile.matches) {


    $.backstretch("Images/bg1-mobil-min.jpg");
    var boxwidth = $('.backstretch').width();

    $(window).resize(function() {
       if (boxwidth != $('body').width() ) { 
         $('.backstretch').removeClass('freeze');
         boxwidth = $('.backstretch').width();
       } else {
         $('.backstretch').addClass('freeze');
         boxwidth = $('.backstretch').width();
       }            
    });

// keep freeze when scroll 
$(document).scroll(function() {
    $('.backstretch').addClass('freeze');
 });

}

好吧......当在移动设备上我们改变旋转 bg chages 但向下滚动时不完美。但是mb有人可以使代码正确。谢谢

于 2016-08-23T11:03:21.680 回答