简体   繁体   English

iOS上未显示背景图片

[英]Background image not showing on iOS

I have a div with a background image applied dynamically with JS. 我有一个带有背景图片的div,该图片使用JS动态应用。 It works great except in iOS - both in iOS Safari & iOS Chrome, the background image just doesn't show. 除了在iOS中以外,它都非常有效-在iOS Safari和iOS Chrome中,背景图片都不会显示。 Very weird I didn't find any answer for that online. 很奇怪,我没有在网上找到任何答案。 Here is how it looks normally: 这是正常的外观:

在此处输入图片说明

And here it how it looks on iOS (ipad and iphone): 这是它在iOS(ipad和iphone)上的外观:

在此处输入图片说明

Here is the CSS, the background-image value was applied by JS: 这是CSS,背景图片值是由JS应用的:

.NavFrame {
  width: 104px;
  height: 58px;
  background-position: center center;
  background-size: cover;
  margin-right: 2%;
  background-image: url(http://www.test.com/test.jpg);
}

Any help will be appreciated. 任何帮助将不胜感激。

UPDATE: Thank you all for the answers, however eventually it was some bug in my JS code. 更新:谢谢大家的回答,但是最终这是我的JS代码中的一些错误。 Anyway hope it can help someone else. 无论如何希望它可以帮助别人。

try like this 这样尝试

.NavFrame {
      width: 104px;
      height: 58px;
      background-position: center center;

      margin-right: 2%;
      background-image: url(http://www.test.com/test.jpg);
      background-size: cover; 
    }

Set the background-size after background-image : background-image 之后设置background-size

.NavFrame {
  width: 104px;
  height: 58px;
  margin-right: 2%;
  background-image: url(http://www.test.com/test.jpg);
  background-position: center center;
  background-size: cover;
}

Or shorthand: 或速记:

.NavFrame {    
  background: url(http://www.test.com/test.jpg) center center / cover;
}

This issue is already discussed in stackoverflow pl. stackoverflow pl中已经讨论了此问题。 refer to the below link Background image not showing on iPad and iPhone 请参阅以下链接iPad和iPhone上未显示背景图片

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

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