Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当网页上显示的数据发生变化时,如何使网页不滚动到顶部_Javascript_Html_Angularjs - Fatal编程技术网

Javascript 当网页上显示的数据发生变化时,如何使网页不滚动到顶部

Javascript 当网页上显示的数据发生变化时,如何使网页不滚动到顶部,javascript,html,angularjs,Javascript,Html,Angularjs,很抱歉这个奇怪的标题,但找不到更好的解释 我有SpringWebApp,它在一个页面上有类似于社交网络的内容。在angularjscontroller中,我有一个数组,在其中存储要在视图中显示的帖子。因此,使用ng repeat我在控制器中显示该数组的内容。在页面底部,我有一个按钮,可以加载更多的帖子(因为我不想一次显示所有可能的帖子),我将新帖子添加到数组中,实际页面上的列表将更新并显示加载的帖子,但当我单击加载更多帖子的按钮时,浏览器会滚动到页面顶部,有没有一种方法可以禁用滚动到顶部的功能

很抱歉这个奇怪的标题,但找不到更好的解释

我有SpringWebApp,它在一个页面上有类似于社交网络的内容。在
angularjs
controller中,我有一个数组,在其中存储要在视图中显示的帖子。因此,使用
ng repeat
我在控制器中显示该数组的内容。在页面底部,我有一个按钮,可以加载更多的帖子(因为我不想一次显示所有可能的帖子),我将新帖子添加到数组中,实际页面上的列表将更新并显示加载的帖子,但当我单击加载更多帖子的按钮时,浏览器会滚动到页面顶部,有没有一种方法可以禁用滚动到顶部的功能

这是我的代码的缩写版本

html:



{{activity.activity.datum}

{{activity.activity.tempo}/km{{activity.activity.distance}}km




js

$scope.loadMore=function(){
$scope.getActivities(3,$scope.currentPage+1,$scope.loggedInUser.username)。然后(函数(响应){
$scope.currentPage++;

for(var i=0;i
了解更多信息。

显示按钮的代码和页面的HTML。@AlexK i做了。12345尝试在父容器上溢出-y?尝试将锚点的href属性值替换为
javascript:void(0)
而不是
。您可以使用不同的值,如
href=“#!”
,或者您可以关闭
href
并使用CSS设置链接样式。
    <div class="main" ng-model="activities" ng-repeat="activity in activities">
        <div class="helper" >
        <center>
            <p><img alt="{{activity.user.username}}" ng-src="pictures/{{activity.user.picture}}" height="50px"> </img> </p>
            <p><a href="#" >{{activity.user.username}} </a></p>
            <br />
            <p class="date">{{activity.activity.datum}} </p>
            <p>
            {{activity.activity.tempo}}/km {{activity.activity.distance}} km</p>
            <br />
        </center>
        </div>
        <br/><br/>
    </div>
    <center><a href="#" ng-click="loadMore()">Load more</a></center>
</div>
    $scope.loadMore = function(){
        $scope.getActivities(3 , $scope.currentPage+1 , $scope.loggedInUser.username).then(function(response){
            $scope.currentPage++;

            for(var i = 0; i<response.length; i++){
                $scope.activities.push(response[i]);
            }
        });
    }