TopGit theo dõi markdalgleish/stellar.js trên GitHub, đã đạt 4.6k sao. Stellar.js - Parallax scrolling made easy
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
PLEASE NOTE: This project is no longer maintained. If parallax scrolling is something you care about, please apply to become a contributor to this project.
Parallax scrolling made easy
Full guide and demonstrations available at the official Stellar.js project page.
Download
Get the development or production version, or use a package manager.
Getting Started
Stellar.js is a jQuery plugin that provides parallax scrolling effects to any scrolling element. The first step is to run .stellar() against the element:
// For example:
$(window).stellar();
// or:
$('#main').stellar();
If you're running Stellar.js on 'window', you can use the shorthand:
$.stellar();
This will look for any parallax backgrounds or elements within the specified element and reposition them when the element scrolls.
Mobile Support
Support in Mobile WebKit browsers requires a touch scrolling library, and a slightly tweaked configuration. For a full walkthrough on how to implement this correctly, read my blog post "Mobile Parallax with Stellar.js".
Please note that parallax backgrounds are not recommended in Mobile WebKit due to performance constraints. Instead, use parallax elements with static backgrounds.
Parallax Elements
If you want elements to scroll at a different speed, add the following attribute to any element with a CSS position of absolute, relative or fixed:
<div data-stellar-ratio="2">
The ratio is relative to the natural scroll speed, so a ratio of 0.5 would cause the element to scroll at half-speed, a ratio of 1 would have no effect, and a ratio of 2 would cause the element to scroll at twice the speed. If a ratio lower than 1 is causing the element to appear jittery, try setting its CSS position to fixed.
In order for Stellar.js to perform its calculations correctly, all parallax elements must have their dimensions specified in pixels for the axis/axes being used for parallax effects. For example, all parallax elements for a vertical site must have a pixel height specified. If your design prohibits the use of pixels, try using the 'responsive' option.
Parallax Backgrounds
If you want an element's background image to reposition on scroll, simply add the following attribute:
<div data-stellar-background-ratio="0.5">
As with parallax elements, the ratio is relative to the natural scroll speed. For ratios lower than 1, to avoid jittery scroll performance, set the element's CSS 'background-attachment' to fixed.
Configuring Offsets
Stellar.js' most powerful feature is the way it aligns elements.
All elements will return to their original positioning when their offset parent meets the edge of the screen—plus or minus your own optional offset. This allows you to create intricate parallax patterns very easily.
Confused? See how offsets are used on the Stellar.js home page.
To modify the offsets for all elements at once, pass in the options:
By default, offsets are relative to the element's offset parent. This mirrors the way an absolutely positioned element behaves when nested inside an element with a relative position.
As with regular CSS, the closest parent element with a position of relative or absolute is the offset parent.
To override this and force the offset parent to be another element higher up the DOM, use the following data attribute:
Similar to CSS, the rules take precedence from element, to offset parent, to JavaScript options.
Confused? See how offset parents are used on the Stellar.js home page.
Still confused? See what it looks like with its default offset parents. Notice how the alignment happens on a per-letter basis? That's because each letter's containing div is its default offset parent.
By specifying the h2 element as the offset parent, we can ensure that the alignment of all the stars in a heading is based on the h2 and not the div further down the DOM tree.
Configuring Scroll Positioning
You can define what it means for an element to 'scroll'. Whether it's the element's scroll position that's changing, its margins or its CSS3 'transform' position, you can define it using the 'scrollProperty' option:
Don't have the level of control you need? Write a plugin!
Otherwise, you're ready to get started!
Configuring Everything
Below you will find a complete list of options and matching default values:
$.stellar({
// Set scrolling to be in either one or both directions
horizontalScrolling: true,
verticalScrolling: true,
// Set the global alignment offsets
horizontalOffset: 0,
verticalOffset: 0,
// Refreshes parallax content on window load and resize
responsive: false,
// Select which property is used to calculate scroll.
// Choose 'scroll', 'position', 'margin' or 'transform',
// or write your own 'scrollProperty' plugin.
scrollProperty: 'scroll',
// Select which property is used to position elements.
// Choose between 'position' or 'transform',
// or write your own 'positionProperty' plugin.
positionProperty: 'position',
// Enable or disable the two types of parallax
parallaxBackgrounds: true,
parallaxElements: true,
// Hide parallax elements that move outside the viewport
hideDistantElements: true,
// Customise how elements are shown and hidden
hideElement: function($elem) { $elem.hide(); },
showElement: function($elem) { $elem.show(); }
});
Writing a Scroll Property Plugin
Out of the box, Stellar.js supports the following scroll properties:
'scroll', 'position', 'margin' and 'transform'.
If your method for creating a scrolling interface isn't covered by one of these, you can write your own. For example, if 'margin' didn't exist yet you could write it like so:
Now, you can specify this scroll property in Stellar.js' configuration.
$.stellar({
scrollProperty: 'margin'
});
Writing a Position Property Plugin
Stellar.js has two methods for positioning elements built in: 'position' for modifying its top and left properties, and 'transform' for using CSS3 transforms.
If you need more control over how elements are positioned, you can write your own setter functions. For example, if 'position' didn't exist yet, it could be written as a plugin like this:
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/markdalgleish/stellar.js là nguồn chính thức.
markdalgleish/stellar.js có bao nhiêu sao?
markdalgleish/stellar.js có 4.6k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/markdalgleish/stellar.js. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
markdalgleish/stellar.js có phải mã nguồn mở không?
Có — markdalgleish/stellar.js phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/markdalgleish/stellar.js.
markdalgleish/stellar.js còn đang phát triển không?
Commit gần nhất trên markdalgleish/stellar.js là 4.3 năm trước (theo timestamp GitHub). Repo có 1.3k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
markdalgleish/stellar.js dùng license gì?
markdalgleish/stellar.js phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
markdalgleish/stellar.js là gì?
markdalgleish/stellar.js (markdalgleish/stellar.js) là dự án JavaScript trên GitHub. Theo mô tả gốc: Stellar.js - Parallax scrolling made easy
markdalgleish/stellar.js viết bằng ngôn ngữ gì?
markdalgleish/stellar.js chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc stellar.js có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về stellar.js.