Home > Web Front-end > Front-end Q&A > How to add browser size change trigger event in jquery

How to add browser size change trigger event in jquery

WBOY
Release: 2022-01-14 11:59:06
Original
2016 people have browsed it

In jquery, you can use the resize method to add a browser size change trigger event. The function of this method is to generate a resize event when the browser window is resized, or to specify a function to be run when a resize event occurs. The syntax is "$(selector).resize()".

How to add browser size change trigger event in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to add a browser size change trigger event in jquery

When the browser window is resized, the resize event occurs.

The resize() method triggers the resize event, or specifies a function to run when the resize event occurs.

Trigger the resize event

Syntax

$(selector).resize()
Copy after login

Bind the function to the resize event

Syntax

$(selector).resize(function)
Copy after login

function Optional. Specifies the function to run when the resize event occurs.

The example is as follows:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
x=0;
$(document).ready(function(){
$(window).resize(function() {
  $("span").text(x+=1);
});
});
</script>
</head>
<body>
<p>窗口大小被调整过 <span>0</span> 次。</p>
<p>请试着重新调整浏览器窗口的大小。</p>
</body>
</html>
Copy after login

Output result:

How to add browser size change trigger event in jquery

##Related video tutorial recommendation:

jQuery video tutorial

The above is the detailed content of How to add browser size change trigger event in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template