oblador/angular-scroll — 1.5k★ trên GitHub (JavaScript). Scrollspy, animated scrollTo and scroll events for angular.js
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.
Angular is only dependency (no jQuery). 8K minified or 2K gzipped.
Example
Check out the live demo or the source code.
Install
With bower:
$ bower install angular-scroll
With npm (for use with browserify):
$ npm install angular-scroll
You can also download the production version or the development version.
If you prefer a CDN hosted version (which might speed up your load times), check out cdnjs.com/libraries/angular-scroll.
Don't forget to add duScroll to your module dependencies.
angular.element Scroll API
This module extends the angular.element object with a few jQuery like functions. Note that $document is an angular.element, for usage example see below. In case of name collisions existing jQuery or jqlite functions will be preserved, just use the prefixed version: ie .duScrollTo() instead of .scrollTo().
.scrollTo( left, top [, duration [, easing ] ] )
Scrolls the element/window to the specified left/top position. If duration is specified the scrolling is animated for n milliseconds. If easing is ommited the animation will default to the duScrollEasing function.
Convenience function. Works exactly the same as scrollToElement but uses the default values from duScrollOffset, duScrollDuration and duScrollEasing unless otherwise specified.
.scrollTop|scrollLeft( )
Returns current scroll position.
.scrollTop|scrollLeft( top [, duration [, easing ] ] )
Scrolls to specified position in either axis, with optional animation.
.scrollTopAnimated|scrollLeftAnimated( top [, duration [, easing ] ] )
Convenience function like scrollToElementAnimated but for scrollTop/scrollLeft.
Promises
Animated scrolling returns a $q promise, it will resolve when the scrolling has finished or be rejected if cancelled (by starting another scroll animation before it finished).
Example
angular.module('myApp', ['duScroll']).
controller('myCtrl', function($scope, $document) {
var top = 400;
var duration = 2000; //milliseconds
//Scroll to the exact position
$document.scrollTop(top, duration).then(function() {
console && console.log('You just scrolled to the top!');
});
var offset = 30; //pixels; adjust for floating menu, context etc
//Scroll to #some-id with 30 px "padding"
//Note: Use this in a directive, not with document.getElementById
var someElement = angular.element(document.getElementById('some-id'));
$document.scrollToElement(someElement, offset, duration);
}
);
The above example can be achieved by configuration instead of arguments:
angular.module('myApp', ['duScroll'])
.value('duScrollDuration', 2000)
.value('duScrollOffset', 30)
.controller('myCtrl', function($scope, $document) {
$document.scrollTopAnimated(400).then(function() {
console && console.log('You just scrolled to the top!');
});
var someElement = angular.element(document.getElementById('some-id'));
$document.scrollToElementAnimated(someElement);
}
);
Directives
du-smooth-scroll
Provides smooth anchor scrolling.
<a href="#anchor" du-smooth-scroll>Scroll it!</a>
If you, for some reason, do not want to use the href attribute as fallback, just use the du-smooth-scroll attribute instead but without leading #. Example: <a du-smooth-scroll="anchor">.
du-scrollspy
Observes whether the target element is at the top of the viewport (or container) and adds an active class if so. Takes optional offset and duration attributes which is passed on to .scrollTo,
Modifies behavior of du-scrollspy and du-smooth-scroll to observe/scroll within and element instead of the window/document. Good for modals/elements with overflow: auto/scroll.
<div du-scroll-container>
<p id="top">This is the top</p>
<p id="anchor">Scroll to me, or <a href="#top" du-smooth-scroll>the top</a></p>
</div>
If your links lie outside of the scrollable element, wrap them with the du-scroll-container directive and send the element id as argument:
Set the duScrollEasing value to a function that takes and returns a value between 0 to 1. Here's a few examples to choose from.
function invertedEasingFunction(x) {
return 1-x;
}
angular.module('myApp', ['duScroll']).value('duScrollEasing', invertedEasingFunction);
You can also pass a custom easing function as the fourth argument in scrollTo.
Debounce Scroll Events
Set the duScrollSpyWait value in milliseconds to debounce the handler and prevent it from triggering frequent events and increase performance for large pages and/or navigations with expanding nodes.
Set the duScrollGreedy value to true if the elements you are observing are not wrapping the whole section you want to observe, but merely the first one in the section (such as headlines).
Specify on which events on the container the scroll animation should be cancelled by modifying duScrollCancelOnEvents, set to false to disable entirely as shown below. Defaults to scroll mousedown mousewheel touchmove keydown.
The duScrollspy directive fires the global events duScrollspy:becameActive and duScrollspy:becameInactive with an angular.element wrapped element as first argument and the element being spied on as second. This is nice to have if you want the URL bar to reflect where on the page the visitor are, 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/oblador/angular-scroll là nguồn chính thức.
oblador/angular-scroll có bao nhiêu sao?
oblador/angular-scroll có 1.5k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/oblador/angular-scroll. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
oblador/angular-scroll có phải mã nguồn mở không?
Có — oblador/angular-scroll 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/oblador/angular-scroll.
oblador/angular-scroll còn đang phát triển không?
Commit gần nhất trên oblador/angular-scroll là 8.1 năm trước (theo timestamp GitHub). Repo có 231 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
oblador/angular-scroll là gì?
oblador/angular-scroll (oblador/angular-scroll) là dự án JavaScript trên GitHub. Theo mô tả gốc: Scrollspy, animated scrollTo and scroll events for angular.js
Đọc đầy đủ README ở tab phía trên.
Chưa chắc angular-scroll 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ề angular-scroll.