jquery 如何使height返回一个值而不是对象

dwbf0jvd  于 2023-06-22  发布在  jQuery
关注(0)|答案(1)|浏览(128)
window.addEventListener("updatedHeight", (event) => {
  let old = event.detail.height;
  alert(old);
  let newHeight = $(".chatbox_body")[0].scrollHeight;
  alert(newHeight);
  let height = $(".chatbox_body").scrollTop(newHeight - old);

  alert(height);

  window.livewire.emit("updateHeight", {
    height: height,
  });
  alert(height);
});

我尝试让height返回一个值,但它返回的却是一个对象

u1ehiz5o

u1ehiz5o1#

根据MDN docs.scrollTop()用于获取值,.scrollTop(value)用于设置值而不返回值。你可以改变:

let height = $(".chatbox_body").scrollTop(newHeight - old);

致:

$(".chatbox_body").scrollTop(newHeight - old);
let height = $(".chatbox_body").scrollTop();

相关问题