search
HomeWeb Front-endJS TutorialBasic optimization ideas for window resize and scroll events_javascript skills

A colleague used the scroll event to load data in the project, but the result was a tragedy in IE. A simple optimization method is given with obvious results.

As long as the user changes the window size, the size of some internal elements will be recalculated, which may cause the entire page to be re-rendered, ultimately consuming a lot of CPU. For example, when the resize method is called, it will be continuously triggered when the user changes the window size, and lower versions of IE may fall into a state of suspended animation. The same is true for the window's scroll event. When the mouse scrolls or drags the scroll bar, the scroll event will be triggered continuously. If there are too many things to process, lower versions of IE will also fall into suspended animation.

Basic optimization idea: only execute the resize event function once within a certain period of time.

Copy code The code is as follows:

var resizeTimer = null;
$(window) .on('resize', function () {
if (resizeTimer) {
clearTimeout(resizeTimer)
}
resizeTimer = setTimeout(function(){
console.log("window resize");
}, 400);
}
);

Scroll event optimization is the same.
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
scroll是什么按键scroll是什么按键Feb 22, 2023 pm 02:29 PM

scroll是滚动锁定键,是计算机键盘上的功能键。scroll键常用于word和Excel中,在Scroll Lock关闭的状态下,使用翻页键时,单元格选定区域会随之发生移动;但是当按下了Scroll Lock键后,就不会移动选定的单元格。

Vue中如何对图片进行压缩和格式转换?Vue中如何对图片进行压缩和格式转换?Aug 25, 2023 pm 11:06 PM

Vue中如何对图片进行压缩和格式转换?在前端开发中,经常会遇到需要对图片进行压缩和格式转换的需求。特别是在移动端的开发中,为了提高页面加载速度和节省用户流量,对图片进行压缩和格式转换是很关键的。而在Vue框架中,我们可以通过一些工具库来实现对图片的压缩和格式转换。使用compressor.js库进行压缩compressor.js是一款用于压缩图片的JavaS

Python怎么对图片进行resize、裁剪、旋转、翻转Python怎么对图片进行resize、裁剪、旋转、翻转May 10, 2023 am 10:43 AM

对图片进行resize、裁剪、旋转、翻转首先我们的原始图片是10张网上下载尺寸不一的图片,如下:操作1:resize将图片resize到相同尺寸(320,240)fromPILimportImageimporttorchvision.transformsastransforms#使用PIL库读入图片并进行resizedefResizeImage():ifnotos.path.exists(rdir):os.makedirs(rdir)foriinrange(10):im=Image.open(d

键盘scroll灯亮什么意思键盘scroll灯亮什么意思Feb 20, 2023 pm 01:42 PM

键盘scroll灯亮的意思是指“滚动锁”被启用;Scroll Lock键在win系统中不用,但是部分软件会使用到这个功能键,按下此键后,在Excel上、下键滚动时,会锁定光标而滚动页面;如果放开此键,则按上、下键时会滚动光标而不滚动页面。

css 怎么隐藏scrollcss 怎么隐藏scrollJan 28, 2023 pm 02:02 PM

css隐藏scroll的方法:1、在Firefox中,可以通过“scrollbar-width: none; /* Firefox */”属性实现隐藏滚动条;2、在IE浏览器中,可以使用“-ms-prefix”属性定义滚动条样式;3、在Chrome和Safari中,可以用CSS滚动条选择器,然后通过“display:none”隐藏即可。

滚动scroll如何理解滚动scroll如何理解May 23, 2023 pm 01:40 PM

滚动宽高scrollHeight  scrollHeight表示元素的总高度,包括由于溢出而无法展示在网页的不可见部分scrollWidth  scrollWidth表示元素的总宽度,包括由于溢出而无法展示在网页的不可见部分  [注意]IE7-浏览器返回值是不准确的  【1】没有滚动条时,scrollHeight与clientHeight属性结果相等,scrollWidth与clientWidth属性结果相等//120120console.log(test.scrollHeight,test.s

Vue中如何使用v-on:scroll监听滚动事件Vue中如何使用v-on:scroll监听滚动事件Jun 11, 2023 pm 12:14 PM

Vue是目前比较流行的前端框架之一,除了常见的事件监听外,Vue还提供了一种用于监听滚动事件的指令,即v-on:scroll。本文将详细介绍如何在Vue中使用v-on:scroll监听滚动事件。一、v-on:scroll指令基本用法v-on:scroll指令用于监听DOM元素的滚动事件,其基本用法如下:<divv-on:scroll="sc

什么是以太坊scroll?以太坊scroll怎么操作?什么是以太坊scroll?以太坊scroll怎么操作?Feb 15, 2025 pm 10:33 PM

以太坊 Scroll 是一种第 2 层扩展解决方案,旨在通过分片和 ZK-Rollup 技术提升以太坊网络的可扩展性。它结合了这两项技术,将交易并行处理并高效验证,从而大幅提高网络吞吐量并降低交易费用。Scroll 旨在成为以太坊虚拟机 (EVM) 的兼容扩展层,允许用户快速且经济地处理交易。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.