在添加新元素时不滚动到页面底部

时间:2015-06-14 11:33:03

标签: html css angularjs

在时间滚动出现时,在我的`容器'的最后一个子元素上添加新元素。我想向下滚动以将新元素放在浏览器视图中。

我尝试使用'$ anchorScroll`但这不起作用。

HTML

<div class="galleryMenu">
        <!-- <a class="live" ng-click="galleryMenu('live')" href="#">live</a>
        <a class="visual" ng-click="galleryMenu('visual')" href="#">visuals</a> -->
        <a class="projects" ng-click="galleryMenu('projects')" href="#">projects</a> //clicking and calling galleryMenu function
</div>
<!-- Focus needs to be applied here, height of element is 180px -->
<div class="appGallery" ng-show="galleryShow" id="anchor3">
        <a ng-click="galleryChanger('prev')" class="prev" href="#">prev</a>
        <a ng-click="galleryChanger('next')" class="next"  href="#">next</a>
</div>

JS

"use strict";

angular.module("tcpApp")
    .run(['$anchorScroll', function($anchorScroll) {
        $anchorScroll.yOffset = 180; //running here.
    }])
    .controller("homeController", ['$scope','server', '$anchorScroll', '$location', function ($scope, server, $anchorScroll, $location) {

        $scope.galleryMenu = function (gallery) {

        var newHash = 'anchor3';
        if ($location.hash() !== newHash) {
          $location.hash('anchor3');
        } else {
          $anchorScroll();
        }

    }]);

0 个答案:

没有答案