$anchorScroll not working on after back to Index.html page Onsen UI

谁说胖子不能爱 提交于 2020-01-16 05:20:08

问题


Hello I am new in angular JS and Onsen UI. i have problem $anchorScroll not working if only i back to page1 in index.html. everything is fine if i refresh browser. in index.html i have two page :

  1. page1. there is button to navigate to page2
  2. in page2 i have number list : from 1 to 20. After open page2 automatically scroll to list number 5 and the $anchorScroll is working fine.
     $scope.scrollTo = function(elementId) {
         $timeout(function() {
              $location.hash(elementId);
              $anchorScroll();
          });

      };

      init();
      function init(){

        $scope.scrollTo('no-5');

      }

in bottom on the list i have OK button that is back to page1 (index.html) the code is

       $scope.back = function(elementId) {
         $scope.myNavigator.pushPage('index.html');

      };
  1. The problem is after i back to page1 and then navigate to page2 again. this $anchorScroll is not working. why this is happen? i have written the code in codepen the link is below

http://codepen.io/lapisan/pen/LGbbJL


回答1:


If you use myNavigator.pushPage you are adding a new page to the stack. In your case, it's better if you reset the navigator to index.html by using myNavigator.resetToPage method.

$scope.back = function(elementId) {
  $scope.myNavigator.resetToPage('index.html');
};

Here is a fixed version of your CodePen example, hope it helps!

http://codepen.io/andipavllo/pen/LGbQgy



来源:https://stackoverflow.com/questions/34507827/anchorscroll-not-working-on-after-back-to-index-html-page-onsen-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!