javascript - 读取位置指示器 - Chrome 问题

标签 javascript jquery google-chrome

我正在使用此代码:LINK - 以水平方式指示读取位置。

我想调整这个脚本来获取不是整个文档的高度,而是仅获取我的 div 的高度之一。这是原始函数:

var getMax = function(){
return $(document).height() - $(window).height();
}

我尝试用以下代码替换上面的代码:

var getMax = function(){
var content = $("#content");
return content.height();
}

Firefox 中的一切都工作正常,但在 Chrome 中,我的水平栏立即被填满。我该如何解决这个问题?

最佳答案

您可以通过更改 $(window).load(fn) 事件中的 $(document).ready(fn) 来修复此问题。

  • ready 在 DOM 完全加载时触发,在这种情况下,Chrome 中的元素尚未准备好或尚未完全加载
  • load ,而是向您保证页面中的所有资源都已加载,以便您可以安全地对元素进行操作(在您的情况下计算高度)。 This demo适用于 Firefox 和 Chrome。

来自documentation :

The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.


Here一篇文章更深入地解释了 readyload 事件之间的区别。

关于javascript - 读取位置指示器 - Chrome 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32397978/

相关文章:

node.js - 来源显得神秘

javascript - 当用户从列表中选择选项而不单击提交按钮时,如何在页面中显示文本框或选择/选项?

javascript - 比较 php 数组和 javascript 数组相同的数据

jQuery 错误 "x.ready.promise is not a function"和 "Modernizr.prefixed is not a function"/jQuery.noConflict

javascript - Angularjs ng-repeat 与过滤范围对象

jquery - 我需要确保使用 jquery get 或 post 的最新响应

html - <TD> 元素发明了额外的空间只是为了弄乱我的布局

javascript - chrome.browserAction.onClicked.addListener() 弹出窗口

javascript - 为 evt.target 赋值是否会导致仅在 Mobile Safari 中出现错误?

javascript - ajax提交后隐藏div