πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

@scrollmeter/core

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scrollmeter/core

Scrollmeter is a lightweight JavaScript library that visually displays scroll progress on web pages.

1.1.0
Source
npm
Version published
Weekly downloads
4
Maintainers
0
Weekly downloads
Β 
Created
Source

Scrollmeter

npm version downloads license

Scrollmeter is a lightweight JavaScript library that visually displays the scroll progress of web pages.

✨ Key Features

  • 🎯 Display scroll progress with an intuitive progress bar
  • πŸ“Š Timeline feature for quick document structure overview (h1 tags only)
  • πŸ” Quick content preview functionality
  • πŸ’‘ Tooltip providing current position information
  • 🎨 Various customization options
  • πŸ“± Responsive design support

πŸš€ Installation

npm install @scrollmeter/core

or

yarn add @scrollmeter/core

πŸ”§ Usage

Specify an ID for the container element where you want to display scroll progress, and call the createScrollmeter function with that ID as the targetId option.

Javascript

In vanilla JavaScript environments, call the createScrollmeter function after the DOM is fully loaded.

import { createScrollmeter } from '@scrollmeter/core'
import '@scrollmeter/core/dist/index.css'

window.onload = function () {
    createScrollmeter({
        targetId: 'container_id_to_measure',
        useTimeline: true,
        useTooltip: true,
        usePreview: true,
    })
}

React

In React environments, use the useEffect hook to call the createScrollmeter function when the component mounts.

import { useEffect } from 'react'
import { createScrollmeter } from '@scrollmeter/core'
import '@scrollmeter/core/dist/index.css'

function App() {
    const [scrollOptions, setScrollOptions] = useState({
        targetId: 'container_id_to_measure',
        useTimeline: true,
        useTooltip: true,
        usePreview: true,
    })

    useEffect(() => {
        createScrollmeter(scrollOptions)
    }, [])

    return <div id='container_id_to_measure'>{/* Content you want to measure scroll for */}</div>
}

βš™οΈ Configuration Options

  • useTimeline: Enable/disable timeline feature showing document structure
  • useTooltip: Show/hide tooltip displaying current scroll position
  • usePreview: Enable/disable content preview feature
    • ⚠️ Preview feature requires useTooltip to be set to true
    • ⚠️ External images are not included in previews due to CORS restrictions

🎨 Style Customization

javascript

import { createScrollmeter } from '@scrollmeter/core'
import '@scrollmeter/core/dist/index.css'

window.onload = function () {
    let scrollOptions = {
        targetId: 'container_id_to_measure',
        useTimeline: true,
        useTooltip: true,
        usePreview: true,
    }

    const scrollmeter = createScrollmeter(scrollOptions)

    scrollOptions = {
        ...scrollOptions,
        barOptions: {
            color: '#4A90E2',
            height: 10,
            background: 'rgba(0, 0, 0, 0)',
        },
    }

    scrollmeter.updateScrollmeterStyle(scrollOptions)
}

React

import { useEffect } from 'react';
import { createScrollmeter, ScrollmeterOptions } from '@scrollmeter/core'
import '@scrollmeter/core/dist/index.css';

function App() {
    const scrollmeter = useRef<ReturnType<typeof createScrollmeter> | null>(null);
    const [scrollOptions, setScrollOptions] = useState<ScrollmeterOptions>({
        targetId: 'container_id_to_measure',
        useTimeline: true,
        useTooltip: true,
        usePreview: true,
    });

    useEffect(() => {
        if (scrollmeter.current) return;
        scrollmeter.current = createScrollmeter(scrollOptions);
    }, []);

    useEffect(() => {
        if (scrollmeter.current) {
            scrollmeter.current.updateScrollmeterStyle(scrollOptions);
        }
    }, [scrollOptions]);

    return (
        <div id="container_id_to_measure">
            {/* Content you want to measure scroll for */}
        </div>
    );
}

barOptions

PropertyTypeDescriptionDefault
colorstringProgress bar colorrgba(74, 144, 226, 0.9)
heightnumberProgress bar height10
backgroundstringProgress bar backgroundrgba(0, 0, 0, 0)

timelineOptions

PropertyTypeDescriptionDefault
colorstringTimeline color#838383
widthnumberTimeline width4

tooltipOptions

PropertyTypeDescriptionDefault
backgroundstringTooltip background#333
fontColorstringTooltip text colorwhite
fontSizenumberTooltip font size12
paddingInlinenumberTooltip inline padding8
paddingBlocknumberTooltip block padding6
widthnumberTooltip width150

🌟 Demo

Demo

πŸ“ License

MIT License

Copyright (c) 2024 suhyeon-jeon

Keywords

scroll

FAQs

Package last updated on 18 Dec 2024

Did you know?

Socket

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.

Install

Related posts