ANGULARJS Module Learning 1 Anchor Scroll

Source: Internet
Author: User

Good memory is better than bad writing ... As a note, the first to start from anchor Scroll, a cup of coffee time can be read, long do not see:)

    • $anchorScroll () to jump to the definition ID;
    • The hash () method of the $location object replaces the current URL as a hash key;
    • $anchorScroll () reads and jumps to the ID.

In the following simple example, here is the output:

Source index.html--11 line, marked with the Jump ID:

1 <!DOCTYPE HTML>2 <HTMLNg-app= "App">3 <Head>4   <Scriptsrc= "Angular.min.js"></Script>5   <Scriptsrc= "App.js"></Script>6   <MetaCharSet= "Utf-8">7 </Head>8 9 <BodyNg-controller= "Mockcontroller">Ten  <Buttonng-repeat= "(key, value) in numbers"Ng-click= "jumper (key)">{{Key}}</Button> One  <Divng-repeat= "(key, value) in numbers"ID= "{{key}}"> A     <H1>{{Key}}</H1> -     <ol> -       <ulng-repeat= "Item in value">{{Item}}</ul> the     </ol> -  </Div> - </Body> - </HTML>

App.js

1 varDEMOAPP = Angular.module ("app",[])2. Controller ("Mockcontroller",3     function($scope, $location, $anchorScroll) {4$scope. Numbers = {5"Natural number": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"],6"Prime": ["2", "3", "5", "7", "11", "13", "17", "19", "23", "29"]7     };8 9$scope. Jumper =function(key) {Ten $location. hash (key); One $anchorScroll (); A     } -});

ANGULARJS Module Learning 1 Anchor Scroll

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.