简体   繁体   English

jQuery function 不工作只是重新加载

[英]jQuery function not working just reloading

I have this function to adjust the page so that it does not scroll regardless of the device, it works at all, however, when you rotate the screen or when I change the device to inspect Google Chrome, the function does not work well, only if I do the reload on the page that works, I don't know what I'm doing wrong.我有这个 function 来调整页面,使其无论设备如何都不会滚动,它完全可以工作,但是,当您旋转屏幕或更改设备以检查 Google Chrome 时,function 不能正常工作,只有如果我在有效的页面上重新加载,我不知道我做错了什么。 I believe the problem is in the variable h, where it picks up the height, which doesn't pick up the height when modifying or rotating the device, but I'm not sure, I've tried everything我相信问题出在变量 h 中,它在其中获取高度,在修改或旋转设备时不会获取高度,但我不确定,我已经尝试了一切

function changeSize() {
  let h = $(document).height();
  let he = $("header").height();
  let m = $("main").height();
  let f = $("footer").height();
  let l = $("ui-loader").height();
  let x = h - he - m - f - l;
  $("container").css('height', x + 'px');
}

$(document).ready(function() {
  changeSize();
  $(window).resize(function() {
    changeSize();
  });
};

The first issue I see is here:我看到的第一个问题在这里:

  let he = $("header").height();
  let m = $("main").height();
  let f = $("footer").height();
  let l = $("ui-loader").height();
  $("container").css('height', x + 'px');

These do not select any element.这些不 select 任何元素。 Are they Class selectors or ID Selectors?它们是 Class 选择器还是 ID 选择器? I will assume Class selectors for my Example.我将为我的示例假设 Class 选择器。

function changeSize() {
  let h = $(document).height();
  let he = $(".header").height();
  let m = $(".main").height();
  let f = $(".footer").height();
  let l = $(".ui-loader").height();
  let x = h - he - m - f - l;
  $(".container").css('height', x + 'px');
}

$(function() {
  changeSize();
  $(window).on("resize deviceorientation", changeSize);
};

Another issue I see here is that this does not capture any Padding or Margins.我在这里看到的另一个问题是这不会捕获任何填充或边距。

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

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