
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
canvas-scrollbar
Advanced tools
A lightweight, customizable scrollbar implementation for HTML Canvas elements. This library provides an efficient way to add scrolling capabilities to canvas-based applications.
A lightweight, customizable scrollbar implementation for HTML Canvas elements. This library provides an efficient way to add scrolling capabilities to canvas-based applications.
应用于
Canvas的自定义滚动条组件,支持水平和垂直方向滚动,可自定义样式和交互行为。
npm
npm install canvas-scrollbar
browser
https://cdn.jsdelivr.net/npm/canvas-scrollbar/dist/index.min.js
const canvas = document.getElementById('myCanvas')
const scrollbar = new CanvasScrollbar(canvas, {
direction: 'y', // 'y' for vertical, 'x' for horizontal
contentSize: 1000, // Total content height/width
viewportSize: canvas.height, // Visible area size
onscroll: (position, maxScroll) => {
// Handle scroll position changes
console.log('Scrolled to:', position)
},
})
[!TIP]
Vertical scrollbar defaults to right side.
Horizontal scrollbar defaults to bottom side.
new CanvasScrollbar(canvas, options)
canvas (HTMLCanvasElement): The canvas element to attach the scrollbar tooptions (Object): Configuration options| Option | Type | Default | Description |
|---|---|---|---|
x | number | - | Scrollbar's left position |
y | number | - | Scrollbar's top position |
width | number | - | Scrollbar's width |
height | number | - | Scrollbar's height |
direction | string | 'y' | Scroll direction: 'x' or 'y' |
contentSize | number | 0 | Total content size (width for horizontal, height for vertical) |
viewportSize | number | Canvas dimension | Visible area size |
style | object | See below | Scrollbar styling options |
onscroll | function | (pos, max) => {} | Callback when scroll position changes |
| Option | Type | Default | Description |
|---|---|---|---|
color | string | '#000' | Scrollbar thumb color |
backgroundColor | string | '#fff' | Scrollbar track color |
radius | number | 0 | Scrollbar corner radius |
padding | number | 0 | Padding inside the scrollbar track |
draw()Draws the scrollbar on the canvas.
scrollbar.draw()
scroll(delta)Scrolls by the specified amount.
// Scroll down 50 pixels
scrollbar.scroll(50)
scrollTo(position)Scrolls to a specific position.
// Scroll to position 200
scrollbar.scrollTo(200)
update(contentSize, viewportSize)Updates the content and viewport dimensions.
// Update when content changes
scrollbar.update(newContentSize, newViewportSize)
destroy()Removes event listeners and cleans up resources.
scrollbar.destroy()
const canvas = document.getElementById('myCanvas')
const ctx = canvas.getContext('2d')
// Content to be scrolled
const content = {
height: 2000,
render: function (pos) {
// Clear canvas
ctx.clearRect(0, 0, canvas.width, canvas.height)
ctx.save()
ctx.translate(0, -pos)
ctx.fillStyle = '#007bff'
for (let y = 0; y < content.height; y += 100) {
for (let x = 0; x < canvas.width; x += 100) {
ctx.fillRect(x + 10, y + 10, 80, 80)
}
}
ctx.restore()
},
}
// Create scrollbar
const scrollbar = new CanvasScrollbar(canvas, {
direction: 'y',
contentSize: content.height,
style: {
color: '#555',
backgroundColor: '#eee',
radius: 5,
padding: 2,
},
onscroll: (position) => {
// Redraw content at new scroll position
content.render(position)
},
})
// Initial render
content.render(0)
scrollbar.draw()
MIT © Mariner
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
A lightweight, customizable scrollbar implementation for HTML Canvas elements. This library provides an efficient way to add scrolling capabilities to canvas-based applications.
The npm package canvas-scrollbar receives a total of 0 weekly downloads. As such, canvas-scrollbar popularity was classified as not popular.
We found that canvas-scrollbar demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.