小白教程
所有教程
关于
Search
172.70.127.123
172.70.127.123
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Event resize”的源代码
本页内容
上一节:
Event_ready
下一节:
Event_scroll
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:resize()}}[[Category:jquery ref events|49]] = jQuery resize() 方法 = [[jquery ref events|jQuery 事件方法]] 对浏览器窗口调整大小进行计数: <sample title="" desc="" lang="html" hererun="1"> $(window).resize(function(){ $('span').text(x+=1); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> x=0; $(document).ready(function(){ $(window).resize(function(){ $("span").text(x+=1); }); }); </script> </head> <body> <p>窗口重置了 <span>0</span> 次大小。</p> <p>尝试重置窗口大小。</p> </body> </html> </run> == 定义和用法 == 当调整浏览器窗口大小时,发生 resize 事件。 resize() 方法触发 resize 事件,或规定当发生 resize 事件时运行的函数。 == 语法 == 触发被选元素的 resize 事件: $(selector).resize() <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> x=0; $(document).ready(function(){ $(window).resize(function(){ $("span").text(x+=1); }); $("button").click(function(){ $(window).resize(); }); }); </script> </head> <body> <p>窗口重置了 <span>0</span> 次大小。</p> <button>触发窗口的 resize 事件</button> </body> </html> </run> 添加函数到 resize 事件: $(selector).resize(function) <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> x=0; $(document).ready(function(){ $(window).resize(function(){ $("span").text(x+=1); }); }); </script> </head> <body> <p>窗口重置了 <span>0</span> 次大小。</p> <p>尝试重置窗口大小。</p> </body> </html> </run> {| class="table table-striped table-hover" ! 参数 ! 描述 |- | function | 可选。规定当 resize 事件被触发时运行的函数。 |} [[jquery ref events|jQuery 事件方法]]
返回至“
Event resize
”。
上一节:
Event_ready
下一节:
Event_scroll