Coder Social home page Coder Social logo

anchorjs's Introduction

AnchorJS Build Status devDependency Status

AnchorJS logo

A tiny JavaScript utility for adding deep anchor links (like these) to existing page content.

Anchoring links

By default, AnchorJS displays a link icon appended to an element which is made visible on hover.

See the demo for an example.

Deep links are useful for linking to specific places in online books and documentation (like, for example, this README file when rendered on the Github project page--hover over headings to see what I mean).

Including AnchorJS

Include the anchor.js file (or alternatively anchor.min.js) in your webpage.

<script src="anchor.js"></script>

For the default anchor link styling (demonstrated in the demo) you should also include anchor.css.

<link rel="stylesheet" href="anchor.css">

Alternatively, you can provide your own styling.

Using AnchorJS

AnchorJS provides the addAnchors() method for adding anchors to the page. This method accepts a selector as a parameter in the form of a string. The selector can be used to target specific elements that you want to add anchors to. Here's an example.

/**
 * Example 1
 * Add anchors to all h1's on the page
 */
addAnchors('h1');

/**
 * Example 2
 * Adds anchors to elements that have been assigned the class '.anchored'
 */
addAnchors('.anchored');

/**
 * Example 3
 * Adds anchors to all h1, h2, & h3's inside a container with an ID of '#post'
 */
addAnchors('#post h1, #post h2, #post h3');

/**
 * Example 4
 * If no selector is provided, it falls back to a default selector of 'h1, h2, h3, h4, h5, h6'
 * which adds anchors to all headings.
 */
addAnchors();

Compatibility

Currently Supports: IE9+ and modern browsers

License

Licensed with the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.