• [AngularJS] Using $anchorScroll


    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" }; } })
  • 相关阅读:
    asp.net 用户页面权限判断
    asp.net Forms表单验证授权
    asp.net 数据绑定
    asp.net 初识
    .net 中ashx文件的应用理解
    记录第一次给linux配置网络,在虚拟机中连接真实网络
    linux 常用命令
    oracle 建分区表,时间自增
    python(9)- python基础知识刷题
    孤荷凌寒自学python第123天区块链037以太坊的 erc20代币07
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4185909.html
Copyright © 2020-2023  润新知