
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@terrahq/anchor-to
Advanced tools
The `AnchorTo` class enables smooth scrolling between elements on a webpage. It provides options for configuring scroll speed, offset, URL updates, debugging, and custom event emissions. Ideal for Single Page Applications (SPAs) and sites requiring a smoo
The AnchorTo
class enables smooth scrolling between elements on a webpage. It provides options for configuring scroll speed, offset, URL updates, debugging, and custom event emissions. Ideal for Single Page Applications (SPAs) and sites requiring a smooth scrolling experience.
npm install terrahq/anchor-to
import AnchorTo from "terrahq/anchor-to";
const anchor = new AnchorTo({
trigger: document.querySelector(".my-button"), // The button that triggers scrolling
destination: document.querySelector("#section4"), // The target element to scroll to
offset: 50, // Offset in pixels or a function for dynamic offset
url: "hash", // URL behavior: 'hash', 'query', or 'none'
speed: 500, // Scroll speed in milliseconds
emitEvents: true, // Emits start and end events for custom listeners
popstate: true, // Supports browser back/forward navigation
debug: true, // Enables console debug output
onComplete: () => console.log("Scroll complete!"), // Callback executed after scroll ends
});
trigger {HTMLElement}
- The element that triggers the scroll when clicked.
destination {HTMLElement}
- The target element to scroll to.
destinationSelector {string}
- The selector of the target element to scroll to.
offset {number | function}
- Distance from the target. Can be a static number or a function that receives destination and trigger as parameters.
url {string}
- Determines URL behavior:
speed {number}
- Duration of scroll animation in milliseconds (default is 1500).
emitEvents {boolean}
- Emits custom events anchorToStart and anchorToEnd during scroll.
popstate {boolean}
- Enables scroll behavior for back/forward navigation.
debug {boolean}
- If true, logs configuration and instance properties to the console.
onComplete {function}
- A callback function executed when the scroll animation completes.
beforeScroll {function}
- A callback function executed before the scroll animation starts.
heightModifyingLibraries {array}
- TERRA EXCLUSIVE - Contains libraries that modify the height of the page
Manager {object}
- TERRA EXCLUSIVE - Library Manager for the Terra Framework
Triggers a scroll animation to the specified element.
// Manually trigger the scroll to the destination element
anchor.scrollTo(anchor.DOM.destination);
Removes event listeners on the trigger and window, cleaning up the instance.
// Removes the click and popstate event listeners
anchor.destroy();
With emitEvents enabled, AnchorTo dispatches custom events:
const anchor = new AnchorTo({
trigger: document.querySelector(".my-button"),
destination: document.querySelector("#section4"),
emitEvents: true,
});
anchor.DOM.trigger.addEventListener("AnchorToStart", (event) => {
console.log("Scrolling has started!", event.detail.element);
});
anchor.DOM.trigger.addEventListener("AnchorToEnd", (event) => {
console.log("Scrolling has ended!", event.detail.element);
});
Three handler functions: handleClick()
, handleSelectChange()
and handlePopstate()
manage the scroll in the three different scenarios that the library will work in.
handlePopstate()
Manages the query present in the URL bar and scrolls there.
handlePopstate() {
const destinationID =
this.url === "query"
? new URLSearchParams(window.location.search).get("scrollto")
: window.location.hash.substring(1);
const destinationElement = document.getElementById(destinationID);
if (destinationElement) {
this.scrollTo(destinationElement);
}
}
handleClick()
Manages a click in a simple HTML element and scrolls there.
async handleClick(event) {
event.preventDefault();
this.handleScroll();
}
handleSelectChange()
Manages the change event of a select
element and scrolls to the value of the input.
async handleSelectChange(event) {
const value = event.target.value;
this.destinationSelector = value;
this.DOM.destination = document.getElementById(this.destinationSelector);
this.handleScroll();
}
FAQs
The `AnchorTo` class enables smooth scrolling between elements on a webpage. It provides options for configuring scroll speed, offset, URL updates, debugging, and custom event emissions. Ideal for Single Page Applications (SPAs) and sites requiring a smoo
We found that @terrahq/anchor-to demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.