jQuery 事件 - resize() 方法

1.定义
当调整浏览器窗口大小时,发生扔resize事件。

2.语法
   1).$(选择器).resize();
   2).$(选择器).resize(function(){});

3.例子:
   1). 例子1
    <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);
  });
  $("button").click(function(){
    $(window).resize();
  });
});
           </script>
        </head>
        <body>
           <p>窗口的大小被调整了 <span>0</span> 次。</p>
           <p>请试着调整浏览器窗口的大小。</p>
           <button>触发窗口的 resize 事件</button>
       </body>
       </html>

    2).例子2
       <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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章