javascript - ".resize"事件与 't work with "偏移量“在一起

标签 javascript jquery

谁能告诉我这段代码有什么问题吗?它只会使我的浏览器崩溃,仅此而已......

$(window).resize(function() {
    var p = $("#outer_wrap");
    var offset = p.offset();
    alert("left: " + offset.left + ", top: " + offset.top);
});

最佳答案

尽量不要使用alert函数,而是使用console.log(确保控制台窗口打开),这对我有用。这可能是由于跨浏览器处理 resize 事件引起的(某些浏览器在调整窗口大小时不断发送该事件。

来自jQuery :

Code in a resize handler should never rely on the number of times the handler is called. Depending on implementation, resize events can be sent continuously as the resizing is in progress (the typical behavior in Internet Explorer and WebKit-based browsers such as Safari and Chrome), or only once at the end of the resize operation (the typical behavior in some other browsers such as Opera).

关于javascript - ".resize"事件与 't work with "偏移量“在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9989405/

相关文章:

javascript - jqTransform Select - 滚动到键入的字母

javascript - CSS jQuery - 在我的 slider 中使用元素符号作为指示器

javascript - 当我更改选项时将 <select> 与来自 json 的数据连接起来

javascript - 使用 jquery 滚动时替换 html 类

javascript - 部分 View 中的 angularjs Controller 脚本不起作用

javascript - Ember JS 和迭代而不影响结果计数

javascript - 从所选按钮中添加类和删除类

javascript - stoppropagation 在 Angular 8 中未按预期工作

javascript - D3.js 如何获取 x 和 y 轴的位置/偏移量

jquery - Owl Carousel 自动播放无法正常工作?