This article mainly introduces the anchor point floor jump function implemented by AngularJS, and involves the related operating skills of AngularJS event response to implement the anchor point jump function. Friends in need can refer to the following
The examples in this article are described Anchor point floor jump function implemented by AngularJS. Share it with everyone for your reference, the details are as follows:
<!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="UTF-8"> <title>anchor</title> <style> #wei p{ width:100%; height:720px; background: red; color:#fff; text-align:center; line-height: 720px; margin:20px; font-size: 80px; } #wei ul{ position: fixed; top:300px; right:60px; } #wei ul li{ width:20px; display:block; height:20px; background: gray; color:#fff; text-align:center; line-height: 20px; border-radius: 50%; margin-bottom: 20px; cursor: pointer; } </style> </head> <body ng-controller="show"> <p id="wei"> <p ng-repeat="attr in arr" ng-attr-id="p{{attr}}">{{attr}}</p> <ul><!-- 定义右边的点 --> <li ng-repeat="attr in arr" ng-click="jump('p'+attr)">{{attr}}</li> </ul> </p> <script src="angular.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> var app = angular.module('myApp',[]); app.controller('show',['$scope','$location','$anchorScroll',function($scope,$location,$anchorScroll){ $scope.arr=[1,2,3,4,5]; $scope.jump=function(id){ //console.log(id); $location.hash(id);//添加锚点 $anchorScroll(); //重新定义服务,解决当滑动时点击锚点无作用的bug } }]); </script> </body> </html>
The running effect is as follows:
Click on the anchor point 2:
Click on the anchor point 3:
#The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to configure multi-site vhost in Nginx
How to implement background data sending in express mockjs
Use mock.js to generate random data
The above is the detailed content of How to implement jump function in AngularJS. For more information, please follow other related articles on the PHP Chinese website!