2016-02-11 28 views
5

我创建了一个侧块,默认情况下为static,但在滚动到某个点时变为fixed。在这个块中,我使用Angular-Material选择。角度材质选择在固定块上奇怪地动作

CSS:

.pos-fixed { 
    position:fixed; 
    top: 60px; 
    width:16.5%!important; 
} 

#sidebar-right { 
    float:right; 
    width:23%; 
} 
#sidebar-right #widget { 
    width:100%; 
} 

HTML:

<div id="sidebar-right"> 
    <div id="widget" ng-class="{'pos-fixed': imageHidden}" class="panel md-padding"> 
     <div> 
     <md-input-container style="width:100%"> 
      <md-select ng-model="number1" placeholder="number 1"> 
      <md-option ng-repeat="number in ['one','two','three','four','five','six','seven']" value="{{number}}">{{number}}</md-option> 
      </md-select> 
     </md-input-container> 
     <br /> 
     <md-input-container style="margin-top: 0px;width:100%"> 
      <md-select ng-disabled="!number1" ng-model="number2" placeholder="numbe 2"> 
      <md-option ng-repeat="number in ['one','two','three','four','five','six','seven']" value="{{number}}">{{number}}</md-option> 
      </md-select> 
     </md-input-container> 
     </div> 
    </div 

JS(滚动间谍):

app.directive('scroll', function($window) { 
    return function(scope, element, attrs) { 
    angular.element($window).bind('scroll', function() { 
     if (this.pageYOffset >= 320) { 
     scope.imageHidden = true; 
     } else { 
     scope.imageHidden = false; 
     } 
     scope.$apply(); 
    }); 
    }; 
}); 

前侧块是fixed,材料选择工作正常,但只要当你滚动,它变成fixed,选择开始行为怪异。
GIF:http://recordit.co/i72EaaVxJf
Plunker:http://plnkr.co/edit/lfik78wR2FqPoSFSCNlz?p=preview

我怎样才能解决这个问题?

+0

可以请你多一点清楚什么古怪的行为? –

+0

请定义“行为奇怪” – peterpeterson

+0

*“行为怪异”*不是一个适当的问题描述。演示对我很好。你是否在多个浏览器中看到相同的问题? – charlietfl

回答

1

添加到您的控制器,而不是scroll指令:

var body = document.querySelector('body'); 
angular.element($window).bind('scroll', function() { 
    if (body.style.position !== 'fixed') { 
    $scope.isFixed = window.scrollY > 330; 
    $scope.$applyAsync(); 
    } 
});