JavaScript - Simple Anchor Scroll Using AngularJS

Submitted by: 
Language: 
Visitors have accessed this post 230 times.

In this tutorial we will create a Simple Anchor Scroll Using AngularJS. AngularJS is a structural framework for dynamic web apps. It is a kind of template that extends HTML to a new level of coding techniques. It is mostly used by other well known site for creating a template.

Getting started:

First you will need to download & install the AngularJS here's the link https://angularjs.org/.

Creating the Main Interface

This code contains the interface of the application. This code will render application and display the form. To do that just kindly write these block of code inside the text editor and save this as index.html.

  1. <!DOCTYPE html>
  2. <html lang="en" ng-app="apps">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" />
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
  6. <script src="js/angular.js"></script>
  7. <script src="js/script.js"></script>
  8. </head>
  9. <body ng-controller="controller">
  10. <nav class="navbar navbar-default">
  11. <div class="container-fluid">
  12. <a class="navbar-brand" href="<a href="https://sourcecodester.com">Sourcecodester</a>
  13. " rel="nofollow">https://sourcecodester.com">Sourcecodester</a>
  14. </a> </div>
  15. </nav>
  16. <div class="col-md-3"></div>
  17. <div class="col-md-6 well">
  18. <h3 class="text-primary">JavaScript - Simple Anchor Scroll Using AngularJs</h3>
  19. <hr style="border-top:1px dotted;"/>
  20. <center><button class="btn btn-success" id="top" ng-click="scrollTo('bottom')"><span class="glyphicon glyphicon-arrow-down"></span> Go to Bottom</button></center>
  21. <br /><br />
  22. <div>
  23. <h1>What Is AngularJS?</h1>
  24. <p>AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.</p>
  25. <p>AngularJS is what HTML would have been, had it been designed for applications. HTML is a great declarative language for static documents. It does not contain much in the way of creating applications, and as a result building web applications is an exercise in what do I have to do to trick the browser into doing what I want?</p>
  26. <p>The impedance mismatch between dynamic applications and static documents is often solved with:</p>
  27. <ul>
  28. <li><strong>a library</strong> - a collection of functions which are useful when writing web apps. Your code is in charge and it calls into the library when it sees fit. E.g., jQuery.</li>
  29. <li><strong>frameworks</strong> - a particular implementation of a web application, where your code fills in the details. The framework is in charge and it calls into your code when it needs something app specific. E.g., durandal, ember, etc.</li>
  30. </ul>
  31. <h1>A complete client-side solution</h1>
  32. <p>AngularJS is not a single piece in the overall puzzle of building the client-side of a web application. It handles all of the DOM and AJAX glue code you once wrote by hand and puts it in a well-defined structure. This makes AngularJS opinionated about how a CRUD (Create, Read, Update, Delete) application should be built. But while it is opinionated, it also tries to make sure that its opinion is just a starting point you can easily change. AngularJS comes with the following out-of-the-box:</p>
  33. <ul>
  34. <li>Everything you need to build a CRUD app in a cohesive set: Data-binding, basic templating directives, form validation, routing, deep-linking, reusable components and dependency injection.</li>
  35. <li>Testability story: Unit-testing, end-to-end testing, mocks and test harnesses.</li>
  36. <li>Seed application with directory layout and test scripts as a starting point.</li>
  37.  
  38. </ul>
  39. </div>
  40. <br />
  41. <center><button class="btn btn-success" id="bottom" ng-click="scrollTo('top')"><span class="glyphicon glyphicon-arrow-up"></span> Go To Top</button></center>
  42. </div>
  43. </body>
  44. </html>

Creating the Script

This code contains the main function of the application. This code will automatically jump to the target page container without scrolling. To that just kindly copy and write these block of codes inside the text editor, then save it as script.js

  1. var apps = angular.module("apps", [])
  2. .controller("controller", function($scope, $location, $anchorScroll){
  3. $scope.scrollTo = function (scrollTarget){
  4. $location.hash(scrollTarget);
  5. $anchorScroll();
  6. }
  7. });

There you have it we successfully created a Simple Anchor Scroll Using AngularJS. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.