概述
俗话说的好:好记性不如一个烂笔头,本文对angularjs模块学习笔记,首先我们从anchor scroll开始学习,具体内容请看下文:
•$anchorScroll()用于跳转至定义ID;
•$location对象的hash()方法会替换当前url作为hash键;
•$anchorScroll()读取并跳转至ID处。
下面简单的例子,这里是输出结果:
源码 index.html--11行,标示了的跳转ID:
<!DOCTYPE html> <html ng-app="app"> <head> <script src="angular.min.js"></script> <script src="app.js"></script> <meta charset="utf-"> </head> <body ng-controller="MockController"> <button ng-repeat="(key, value) in numbers" ng-click="jumper(key)"> {{key}} </button> <div ng-repeat="(key, value) in numbers" id="{{key}}"> <h>{{key}}</h> <ol> <ul ng-repeat="item in value"> {{item}} </ul> </ol> </div> </body> </html>
app.js
var demoApp = angular.module("app",[]) .controller("MockController", function ($scope, $location, $anchorScroll) { $scope.numbers = { "自然数":["","","","","","","","","","","","","","","","","","","",""], "质数":["","","","","","", "", "", "", ""] }; $scope.jumper = function(key){ $location.hash(key); $anchorScroll(); } });
以上所述是小编给大家整理的AngularJS模块学习之Anchor Scroll 的相关内容,希望大家喜欢。
最后
以上就是幸福篮球为你收集整理的AngularJS模块学习之Anchor Scroll的全部内容,希望文章能够帮你解决AngularJS模块学习之Anchor Scroll所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复