首页 > Web开发 > 详细

[AngularJS] Using $anchorScroll

时间:2014-12-26 00:54:47      阅读:340      评论:0      收藏:0      [点我收藏+]

If you‘re in a scenario where you want to disable the auto scrolling, but you want to control the scrolling manually, you can use the anchorscroll service, and then just invoke that after some hash has changed.

 

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body ng-app="egghead" ng-controller="AppCtrl as app">

<a ng-click="app.goToAnchor(elm)" ng-repeat="elm in app.elms">{{elm}}</a>
<div id="{{elm}}" ng-style="app.createStyle($index)" ng-repeat="elm in app.elms">
    {{elm}}
</div>

<script src="//cdn.jsdelivr.net/tinycolor/0.9.16/tinycolor.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="app.js"></script>
</body>
</html>
var app = angular.module("egghead", []);

app.config(function ($anchorScrollProvider) {
    $anchorScrollProvider.disableAutoScrolling();
})

app.controller("AppCtrl", function ($location, $anchorScroll) {
    var app = this;

    app.elms = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");

    //https://github.com/bgrins/TinyColor#color-combinations
    var colors = tinycolor.analogous("steelblue", app.elms.length, app.elms.length);

    app.goToAnchor = function (elm) {
        $location.hash(elm);
//call when you when it scroll $anchorScroll(); } app.createStyle
= function (index) { var color = colors[index]; //grabs a tinycolor of the array return { backgroundColor: color.toHexString(), borderBottom: "3px solid black", height: "100px" }; } })

 

[AngularJS] Using $anchorScroll

原文:http://www.cnblogs.com/Answer1215/p/4185909.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!