2011-12-20 54 views
1

我試圖使用tinyscrollbar插件http://baijs.nl/tinyscrollbar/tinyScroll未啓用

這樣的:

$('#nvl2 .content').html('<div class="scrollbar">'+ 
             '<div class="track">'+ 
              '<div class="thumb"><div class="end"></div></div>'+ 
             '</div>'+ 
            '</div>'+ 
            '<div class="viewport">'+ 
             '<div class="overview">' +$('#nvl2 .content').html()+'</div>'+ 
            '</div></div>' ).attr('id','sc2'); 

       $('#sc2').tinyscrollbar(); 

這是在#NVL2加載新的內容,但tinyscroll不是Ajax調用之前右稱爲啓用,螢火蟲不跳任何錯誤

CSS:

/**************/ 
/* Tiny Scrollbar */ 
#nvl1 { } 
#nvl1 .viewport { ¡overflow: hidden; position: relative; width:100% } 
#nvl1 .overview { list-style: none; position: absolute; left: 0; top: 0; padding: 0; margin: 0; } 
#nvl1 .scrollbar{ background: transparent url(../images/bg-scrollbar-track-y.png) no-repeat 0 0; position: relative; background-position: 0 0; float: right; width: 15px; } 
#nvl1 .track { background: transparent url(../images/bg-scrollbar-trackend-y.png) no-repeat 0 100%; height: 100%; width:13px; position: relative; padding: 0 1px; } 
#nvl1 .thumb { background: transparent url(../images/bg-scrollbar-thumb-y.png) no-repeat 50% 100%; height: 20px; width: 25px; cursor: pointer; overflow: hidden; position: absolute; top: 0; left: -5px; } 
#nvl1 .thumb .end { background: transparent url(../images/bg-scrollbar-thumb-y.png) no-repeat 50% 0; overflow: hidden; height: 5px; width: 25px; } 
#nvl1 .disable { display: none; } 

/**************/ 
/* Tiny Scrollbar */ 
#nvl2{ } 
#nvl2 .viewport { ¡overflow: hidden; position: relative; width:100% } 
#nvl2 .overview { list-style: none; position: absolute; left: 0; top: 0; padding: 0; margin: 0; } 
#nvl2 .scrollbar{ background: transparent url(../images/bg-scrollbar-track-y.png) no-repeat 0 0; position: relative; background-position: 0 0; float: right; width: 15px; } 
#nvl2 .track { background: transparent url(../images/bg-scrollbar-trackend-y.png) no-repeat 0 100%; height: 100%; width:13px; position: relative; padding: 0 1px; } 
#nvl2 .thumb { background: transparent url(../images/bg-scrollbar-thumb-y.png) no-repeat 50% 100%; height: 20px; width: 25px; cursor: pointer; overflow: hidden; position: absolute; top: 0; left: -5px; } 
#nvl2 .thumb .end { background: transparent url(../images/bg-scrollbar-thumb-y.png) no-repeat 50% 0; overflow: hidden; height: 5px; width: 25px; } 
#nvl2 .disable { display: none; } 

這是一次Ajax調用完成內容的樣本

<div class="level" id="nvl2" style="left: 540px; display: block; height: 663px; z-index: 1;"> 
    <div class="content" style="display: block;"> 
     <div class="scrollbar"> 
      <div class="track"> 
       <div class="thumb"> 
        <div class="end"> 
        </div> 
       </div> 
      </div> 
     </div> 
     <div class="viewport"> 
      <div class="overview"> 
       <span class="close"></span> 
       <div class="contentHeader"> 
        <div class="contentHeaderImg"> 
         <img alt="redLevel" class="attributeImgLogo" src="img/cnt/redLevel.png"> 
        </div> 
        <h2>Red Level Glove</h2> 
        <h4>The boutique hotel within the hotel</h4> 
       </div> 
       <div class="contentImg"> 
        <img class="attributeImg" alt="drink" src="img/cnt/redLevelDrink.jpg"> 
       </div> 
       <div class="contentTxt"> 
        <p> 
         Red Level Lounge: Exclusive VIP Red Level Lounge featuring private check-in with a welcome glass of Veuve Clicquot Grande Dame champagne. 
        </p> 
        <p> 
         The Red Level Family Concierge experience is offered in select resort locations. Luxuries include separate VIP check-in lounge exclusively for Family Concierge clients, designated family pools, premium suite accommodations designed with families in mind, upgraded ensuite amenities. 
        </p> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div class="extra" style="width: 418px;"> 
    </div> 
</div> 

而AJAX調用之前和tinyscrollbar初始化exectuted:

<div class="level" id="nvl2" style="left: 540px; display: block; height: 663px; z-index: 1;"> 
     <div class="content" style="display: block;"> 
        <span class="close"></span> 
        <div class="contentHeader"> 
         <div class="contentHeaderImg"> 
          <img alt="redLevel" class="attributeImgLogo" src="img/cnt/redLevel.png"> 
         </div> 
         <h2>Red Level Glove</h2> 
         <h4>The boutique hotel within the hotel</h4> 
        </div> 
        <div class="contentImg"> 
         <img class="attributeImg" alt="drink" src="img/cnt/redLevelDrink.jpg"> 
        </div> 
        <div class="contentTxt"> 
         <p> 
          Red Level Lounge: Exclusive VIP Red Level Lounge featuring private check-in with a welcome glass of Veuve Clicquot Grande Dame champagne. 
         </p> 
         <p> 
          The Red Level Family Concierge experience is offered in select resort locations. Luxuries include separate VIP check-in lounge exclusively for Family Concierge clients, designated family pools, premium suite accommodations designed with families in mind, upgraded ensuite amenities. 
         </p> 
        </div> 
       </div> 

     <div class="extra" style="width: 418px;"> 
     </div> 
    </div> 

,並可以在這裏進行測試:http://toniweb.us/gm什麼是什麼想法我錯過了?

+0

你試過它沒有明確設置微小的滾動的HTML?如果你在AJAX函數完成後調用'$('#nvl2')。tinyscrollbar();',js應該爲你生成。 – Rondel

+0

嘿!謝謝!但那些div不生成和滾動條沒有啓用(基本上我不能apreciate任何改變) –

回答

2

你是怎麼通過

...).attr('sc2'); 
在你的代碼

是什麼意思? 帶有一個參數的函數.attr()是屬性值的getter。你想爲元素設置ID嗎?如果這是你的主意話,最好的辦法是給這個ID插入到這個網站碼:當執行自帶tinyScrollbar初始化排隊

<div id="sc2" class="scrollbar"> 

在您的網頁:

$('#sc2').tinyscrollbar(); 

沒有與id的元素'sc2',這就是爲什麼滾動條沒有顯示出來,並且在螢火蟲中沒有錯誤。

+0

男人你是對的,我編輯的代碼,但結果是非常相似.. –

0

嘗試使用tinyscrollbar_update()方法。當我必須更改ajax請求上的內容時,我遇到了問題。它對我很好。完整的文檔在http://baijs.nl/tinyscrollbar/