2012-06-13 92 views
2

這個想法是,這種手風琴只適用於智能手機,以提高小型設備的可用性。智能手機的jQuery手風琴

但是當你刷新480

有包括函數的東西,使得瀏覽器只要窗口480下調整刷新方式下的瀏覽器,它僅適用?

手動刷新瀏覽器不會使它可用。

var windowWidth = $(window).width(); //retrieve current window width 
function accordion() { 
if (windowWidth<=480) 
{ 


$('h3').click(function() { 

    $('h3').next().hide(2000); 

    if($(this).next().is(':hidden') == true) { 

      $(this).next().show(1000); } 


         }); 

        }} 

$(document).ready(function() { 
accordion(); 
}); 

HTML標記

    <section class="box"> 

         <h3>Service 1</h3> 

         <div class="box2"> <p></p></div> 

        </section><!-- end box_1 --> 

        <section class="box"> 

         <h3>Service 2</h3> 

         <div class="box2"><p></p> </div>      

        </section><!-- end box_2 --> 

        <section class="box"> 

         <h3>Service 3</h3> 

         <div class="box2"><p></p> </div>      

        </section><!-- end box_3 --> 

        </section> 

回答

0

你只得到了最初的窗口的寬度。

$(window).resize(function() { windowWidth = $(this).width(); }); 

您還需要適當地運行accordion,並關閉它,如果窗口再次擴大。也許只需在window.resize方法中加入accordion即可,但我還沒有測試過。