【问题标题】:Why not applied properly in JQuery my calculation?为什么不能在 JQuery 我的计算中正确应用?
【发布时间】:2015-09-09 17:43:16
【问题描述】:

我有这个网站:

link

访问网站首页分辨率较高时出现问题 (放在小的还可以)。

例如对于这个分辨率 (1920x1200) 的网站如下图所示。

代码 JS:

 var screenH = jQuery(window).height();
 console.log("Inaltimea ecranului este:",screenH);
 var headerH=jQuery('header').outerHeight();
 console.log("Inaltimea headerului este:",headerH);
 var footerH=jQuery('footer').outerHeight();
 console.log("Inaltimea footerului este:",footerH);
 var calcul=screenH-headerH-333-2;
 console.log("Rezultatul este:",calcul);
 jQuery('#main').css( "height", calcul );

我把这段代码放在函数window.load函数中。

但不幸的是它不起作用......我没有意识到我的照片直到最后。

你能帮我解决这个问题吗?

提前谢谢]2

【问题讨论】:

  • 你不能将图片设置为背景并使用background-size: cover 吗?
  • 是的...这里 .entry-header img { background-size:cover; }
  • background-size 应用于背景,而不是图像。您需要将图像设置为 background-image 而不是内联图像。
  • 你在 <body> 标签上使用了 img 作为 background 并且还设置了 background-size: 100% 100% ,设置 cover 代替这个,你很高兴。

标签: jquery html css wordpress


【解决方案1】:

您的函数确实有效,但需要一些时间才能被触发。这就是您应该尝试仅使用 css 调整图像大小的确切原因。 background-size 应该自己完成这项工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-09
    • 2014-03-26
    • 2013-12-12
    • 2019-10-12
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 2019-05-02
    相关资源
    最近更新 更多