2014-04-01 46 views
1

我已經使用開發用於角,但它不能正常工作很好的滾動條滾動的指令,任何一個有一些其他的解決辦法滾動條在AngularJs不工作

app.directive('niceScrollDirective', function() { 
return { 
    restrict: 'A', 
    scope: true, 
    link: function(scope, element, attrs) { 

     var niceScrollDefaultObj = { 
      "cursorcolor":"#bdbdbd", 
      "background" :"#ffffff", 
      "cursorwidth": "10px", 
      "cursorborder": "none", 
      "cursorborderradius": "2px", 
      "zindex": 9999, 
      "autohidemode": false 
     } 

     var niceScrollDirectiveObj = scope.$eval(attrs.niceScrollDirective); 
     for(var key in niceScrollDirectiveObj){ 
      niceScrollDefaultObj[key] = niceScrollDirectiveObj[key]; 
     } 
     element.niceScroll(niceScrollDefaultObj); 
    } 
}; 

});

+0

什麼不正常呢?你能舉一個例子說明它與你的期望(小提琴等)以及你如何使用它? – brianj

+0

現在,它的工作,謝謝 –

+0

找到解決方案?我有同樣的問題。你可以分享你在angularjs中用於nicescroll的依賴關係嗎?我正在嘗試這個 https://github.com/tushariscoolster/angular-nicescroll –

回答

0

Hy此代碼適合我。

cv.directive('niceScroll', function() { 
    return{ 
     restrict: 'A', 
     link: function(scope, element, attribute) { 

      var nicescrolConf = { 
       "cursorcolor": "#bdbdbd", 
       "background": "#ffffff", 
       "cursorwidth": "10px", 
       "cursorborder": "none", 
       "cursorborderradius": "2px", 
       "zindex": 9999, 
       "autohidemode": false 
      }; 

      element.niceScroll(nicescrolConf); 
     } 
    }; 
}); 

我的HTML元素:

<div class="container" nice-scroll> 
      <div class="main-content"> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
       <h1>test</h1> 
      </div> 
     </div> 

我的CSS:

.container{ 
    position: fixed; 
    top:0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    overflow: hidden; 
} 

.main-content{ 
    overflow-x: hidden; 
    overflow-y: scroll; 
}