1

私のangularJS Webappには2つの主な問題があります。

  1. ルートが変化している(またはページが変化している)ときにブラウザーが一番上にスクロールするようにしたい-現在、その位置を記憶している-それはちょっと面倒だ。

  2. サブページに 3 つの異なるタブがある 1 つのページがあります。ng-click機能とスムーズなスクロール(アンカー)でそれらをナビゲートできます

私の問題は、このアンカータグをURLに表示したいということです: about/section1 about/section2 about/section3

現在、すべて「約」にとどまっています

これが私のセットアップです:

// 3 Ng click funtions to navigate in the submenue to the sections (all in one page) - but they not showing up in the url tag! 

    angular.module('testApp')
      .value('duScrollDuration', 2000)
      .value('duScrollOffset', 122)
      .controller('ankerCtrl', function($scope, $document){

        var container = angular.element(document.getElementById('container'));
        $scope.toTheTop = function() {
          container.scrollTop(0, 5000);

        }
        $scope.toSection1 = function() {
          console.log("hallooo ich will zu section 1");
          var someElement = angular.element(document.getElementById('section-1'));
          $document.scrollToElementAnimated(someElement);
        }
        $scope.toSection2 = function() {
          console.log("hallooo ich will zu section 2");
          var someElement = angular.element(document.getElementById('section-2'));
          $document.scrollToElementAnimated(someElement);
        }
        $scope.toSection3 = function() {
          console.log("hallooo ich will zu section 3");

          var someElement = angular.element(document.getElementById('section-3'));
          $document.scrollToElementAnimated(someElement);
        }
      }
    );

//Routing
.config(function ($urlRouterProvider, $stateProvider, $anchorScrollProvider) {
    $stateProvider
      .state('about', {
        url: "/about",
        views: {
          'content': {
            templateUrl: 'views/about.html',
            controller: 'MainCtrl'
          },
          'subnavi': {
            templateUrl: 'views/subnavi-about.html'
          }
        }
      }).state('unternehmen', {
        url: "/unternehmen",
        views: {
          'content': {
            templateUrl: 'views/unternehmen.html',
            controller: 'MainCtrl'
          },
          'subnavi': {
            templateUrl: 'views/subnavi-unternehmen.html'
          }
        }
      })
      .state('main', {
        url: "/",
        views: {
          'content': {
            templateUrl: 'views/main.html'
          }
        }
      });

    $urlRouterProvider.otherwise('/');
    $anchorScrollProvider.disableAutoScrolling();

  });

助けてくれてどうもありがとう!

(繰り返します: 1. スクロールして一番上に移動します 2. サブアンカーが URL タグに表示されません

4

0 に答える 0