2016-04-06 51 views
1

ng-show元素中的可滾動內容會忘記Internet Explorer中的滾動位置,但不會在Firefox中。在Internet Explorer和Firefox中運行Plunker to describe the issue。你會得到不同的結果。Internet Explorer中的可滾動元素不記得最後一個位置ng-show

任何人都知道爲什麼?

+1

閱讀**標籤遺漏** [這裏](https://developer.mozilla.org/en/docs/Web/HTML/Element/p)使用'DIV'而不是'P '元素包裝'OL','按鈕','FORM'等... –

+0

@AlonEitan解決了http://plnkr.co/edit/CSwe2LxbxunvLef2HkYB?p=preview – bhantol

+0

中的問題這是一個很好的問題,但我不知道如何解決它。我還建議添加再現步驟(** 1。**)點擊'轉到底部** 2 ** **點擊** hidee ** ** ** **點擊'顯示',並描述預期的結果與實際情況結果) –

回答

1

我可以建議採取以下解決辦法 - 保存在控制器上的位置的狀態,並用它來重新定位:

$scope.position = "top"; // Default location of the list 
    $scope.show = true; 

    $scope.gotoBottom = function() { 
    $location.hash('bottom'); 
    $scope.position = "bottom"; // save the current position 
    $anchorScroll(); 
    }; 

    $scope.gotoTop = function() { 
    $location.hash('top'); 
    $scope.position = "top"; // save the current position 
    $anchorScroll(); 
    }; 

    $scope.toggleShow = function() { 
    $scope.show = !$scope.show; 
    if($scope.position == "bottom") { // If position is "bottom" call "$scope.gotoBottom()" to reset the position 
     $timeout(function() { // The code is inside "$timeout" to allow the view to render before updating the location 
     $scope.gotoBottom(); 
     }); 
    } 
    }; 

並且在這個視圖,改變你的顯示/隱藏列表:

<button ng-click="toggleShow()">{{show ? 'Show' : 'Hide'}}</button> 

而且不要忘記注入$timeout到你的控制器:

.controller('ScrollController', ['$scope', '$location', '$anchorScroll', '$timeout', 
function ($scope, $location, $anchorScroll, $timeout) { 

這裏是一個工作的例子 - http://plnkr.co/edit/oXKpmwQtV8ICRvGNeQby?p=preview

+0

然而,謝謝你的主要問題仍然存在 - 你的解決方案需要照顧頂部/底部,而不是中間或其他任何地方。我想了解這裏的根本問題。 – bhantol

+0

@bhantol這就是爲什麼我建議在我的意見:)再生步驟我沒有想過這個......但檢查解決方案[這裏](http://stackoverflow.com/questions/21015145/ie10-reset-the- scrollbars-position-to-left-left-for-a-block-overflowauto-aft)(檢查答案中的jsfillds) - 他們有可以使用指令在應用中實現的解決方法 –

相關問題