修复移动后放大后的背景图像跳转

时间:2016-06-09 13:22:02

标签: html css twitter-bootstrap mobile browser

我试了这么多!但我认为我的问题比其他解决的问题更加特殊:

这是方面: fruehstarter.com

我的移动设备背景有问题。 我的客户想要一个特殊的背景,它以100%的宽度和高度固定。在移动设备上,您需要放大以识别内容。 但是,如果向下滚动并且浏览器行消失,则背景图像会因新高度而跳跃。

要么我有跳跃的背景,要么我的侧边有一个带有浏览器线高度的白色边框。

希望您了解我的问题,并可以帮助我。非常感谢!

编辑:我尝试了什么:

background:cover not scaling on mobile browsers

Background image jumps when address bar hides iOS/Android/Mobile Chrome

我试图给我的div“.bg”和“.container-fluid”另一个位置(改为“绝对”和“相对”)或给另一个div作为背景。

编辑第二名:

以下是CODE:jsfiddl

HTML:
 <div class="container-fluid">
  <div class="bg"></div> 
   <div class="row">
    <div class="linkbox"></div>
   </div>
 </div>

CSS:

 html {
  font-size: 10vh;
  height: 100%;
  font-family: 'Titillium Web', sans-serif;
 }

 body {
  -webkit-overflow-scrolling: touch;
  min-height: 100%;
  width: 100%;
  position: relative;
 }

 .container-fluid {
  height: 100%;
  overflow-x: hidden;
  position: absolute;
  width: 100%;
 }

 .row {
  height: 100%;
  position: relative;
 }

 .bg {
  overflow: hidden; 
  position: fixed; 
  width: 100%;
  height: auto;
  min-height: 10rem;
  padding-left: 15px;
  padding-right: 15px;
  margin-left: -15px;
  margin-right: -15px;
  z-index: -1; 
  background: url('http://fruehstarter.com/wp- content/themes/fruehstarter/library/images/fs_klingelschildMobil6.jpg') no-repeat;
  background-size: cover;
  -webkit-background-size:cover;
  -moz-background-size:cover;
  -o-background-size:cover;
  background-position: center center;
  background-attachment: fixed;
 }

JAVASCRIPT:

 jQuery(document).ready(function () {
  if (navigator.userAgent.match(/(iPad|iPhone|iPod|Android)/g)) {
    $('html').css('font-size', Math.ceil($(window).height() / 10));
    $('.bg').css('overflow-y', 'scroll');
    $('body').scrollTop(1);
  }
 }

1 个答案:

答案 0 :(得分:0)

分享您的代码会很有帮助。

我认为

background-attachment: fixed; 

另外还有你要找的东西。

示例:

background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;

<强>更新

试试这个:

     body {
         background: url('http://fruehstarter.com/wp- content/themes/fruehstarter/library/images/fs_klingelschildMobil6.jpg') no-repeat;
         background-size: cover;
         -webkit-background-size:cover;
         -moz-background-size:cover;
         -o-background-size:cover;
         background-repeat: no-repeat;
         background-position: center;
         background-attachment: fixed;
     }

我认为在你的情况下,定义身体内部的背景会更舒服。