2012-05-22 64 views
1

請點擊「查看所有」,然後顯示一個彈出。彈出窗口出現,但滾動條不起作用。jquery.tinyscrollbar彈出滾動條不工作

的JavaScript

$(document).ready(function(){ 
    $('#scrollbar1').tinyscrollbar();  
}); 

//SETTING UP OUR POPUP 
//0 means disabled; 1 means enabled; 
var popupStatus = 0; 

//loading popup with jQuery magic! 
function loadPopup(){ 
    //loads popup only if it is disabled 
    if(popupStatus==0){ 
     jQuery("#backgroundPopup").css({ 
      "opacity": "0.7" 
     }); 
     jQuery("#backgroundPopup").fadeIn("slow"); 
     jQuery("#popupContact").fadeIn("slow"); 
     popupStatus = 1; 
    } 
} 

//disabling popup with jQuery magic! 
function disablePopup(){ 
    //disables popup only if it is enabled 
    if(popupStatus==1){ 
     jQuery("#backgroundPopup").fadeOut("slow"); 
     jQuery("#popupContact").fadeOut("slow"); 
     popupStatus = 0; 
    } 
} 

//centering popup 
function centerPopup(){ 
    //request data for centering 
    var windowWidth = document.documentElement.clientWidth; 
    var windowHeight = document.documentElement.clientHeight; 
    var popupHeight = jQuery("#popupContact").height(); 
    var popupWidth = jQuery("#popupContact").width(); 
    //centering 
    jQuery("#popupContact").css({ 
     "position": "absolute", 
     "top": windowHeight/2-popupHeight/2, 
     "left": windowWidth/2-popupWidth/2 
    }); 
    //only need force for IE6 

    jQuery("#backgroundPopup").css({ 
     "height": windowHeight 
    }); 

} 


//CONTROLLING EVENTS IN jQuery 
jQuery(document).ready(function(){ 
    //LOADING POPUP 
    //Click the button event! 
    jQuery("#button").click(function(){ 
     //centering with css 
     centerPopup(); 
     //load popup 
     loadPopup(); 
    }); 

    //CLOSING POPUP 
    //Click the x event! 
    jQuery("#popupContactClose").click(function(){ 
     disablePopup(); 
    }); 
    //Click out event! 
    jQuery("#backgroundPopup").click(function(){ 
     none(); 
    }); 
    //Press Escape event! 
    jQuery(document).keypress(function(e){ 
     if(e.keyCode==27 && popupStatus==1){ 
      disablePopup(); 
     } 
    }); 

}); 

function LoadPop(){ 
     centerPopup(); 
     loadPopup(); 
} 

HTML

<div class="achieve"> 
    <h2><a href="#" id="button">(see all)</a></h2> 
    <div class="achieve-container"> 

    </div> 
</div> 
<div id="popupContact"> 
    <div class="" id="contactArea"> 
      <div class="logbox"> 
       <div id="scrollbar1"> 
       <div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div> 
       <div class="viewport"> 
       <div class="more-achive"> 
        <h2>My Profile <a id="popupContactClose"><img src="images/close.gif" /></a></h2> 
        <div class="spacer"></div> 
        <div class="profstat"> 
         <img src="images/pro-image1.gif" alt="Profile Image" /> 
         <h1>Emily Hsiung</h1> 
         <p><span>567</span> Points</p> 
         <p><span>22</span> achievements</p> 
        </div> 
        <div class="proflevelindicator"> 
         <img src="images/level-indicator.gif" alt="level indicator" /> 
         <h1>Level 5 Elephant Hunter</h1> 
         <p><span>33</span> Points to next level</p> 
        </div> 
        <div class="spacer"></div> 
        <div class="achievelist"> 
         <h2>Achievements</h2> 
         <ul> 
          <li> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">Spotlight</div> 
          </li> 
          <li> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">15 Minutes of Fame</div> 
          </li> 
          <li> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">Contributor</div> 
          </li> 
          <li class="nomar"> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">Super Contributor</div> 
          </li> 
          <li class="nomar1"> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">Share Your Toughts</div> 
          </li> 
          <li class="nomar1"> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">shout From The Rooftops</div> 
          </li> 
          <li class="nomar1"> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">15 Minutes of Fame</div> 
          </li> 
          <li class="nomar"> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">Super Contributor</div> 
          </li> 
          <li class="nomar1"> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">Share Your Toughts</div> 
          </li> 
          <li class="nomar1"> 
           <div class="imagbox"><img src="images/ach6.gif" /></div> 
           <div class="titlebox">shout From The Rooftops</div> 
          </li> 
          <li class="nomar1"> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">15 Minutes of Fame</div> 
          </li> 
          <li style="margin:0 0 0 0;"> 
           <div class="imagbox"><img src="https://encrypted-tbn0.google.com/images?q=tbn:ANd9GcQB1T4_bghGtisR6Tom0Umf3FZHCQoPGFJgD0Orck3cB0F8iTZN" /></div> 
           <div class="titlebox">Contributor</div> 
          </li> 
         </ul> 
        </div> 
       </div> 
       <div class="spacer"></div> 
      </div> 
     </div> 
    </div> 
</div> 
<div class="spacer"></div> 
</div> 
<div id="backgroundPopup"></div> 
+0

我得到JS錯誤,因爲我缺少JS文件,使用螢火蟲時會出現錯誤嗎? – kleinohad

+0

是的,我得到了js錯誤。你如何得到錯過的文件/ – anglimasS

+0

@ t.k - 我的隊友解決了這個問題 – anglimasS

回答

8

JavaScript的錯誤是Uncaught TypeError: Cannot read property 'scrollHeight' of undefinedjquery.tinyscrollbar.js:54。看着the source,它試圖找到與scrollHeight屬性

oContent[options.axis] = oContent.obj[0]['scroll'+ sSize]; 

但oContent被定義爲

var oContent = { obj: $('.overview', root) }; 

有與class="overview"您的標記沒有元素,所以腳本失敗。

我建議遵循您似乎有downloaded the script from的網站中的示例,特別是HTML爲基本滾動條。該腳本期待你的演示中沒有的標記。

0

我看到一個自定義的滾動條,但沒有滾動功能。你可以使用默認的瀏覽器滾動條嗎?

如果您刪除滾動條div並在#scrollbar1 .viewport屬性上將overflow:hidden替換爲overflow:scroll,則該框將使用默認滾動條滾動。

這裏是一個jsfiddle演示。

你總是可以回過頭來用CSS設計滾動條的樣式,請參閱css技巧中的this article

希望有幫助!