gajus/swing hiện có 2.6k sao trên GitHub, viết chủ yếu bằng JavaScript. A swipeable cards interface. The swipe-left/swipe-right for yes/no input. As seen in apps like Jelly and Tinder.
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.
A swipeable cards interface. The swipe-left/swipe-right for yes/no input. As seen in apps like Jelly and Tinder, and many others.
Give it a swing! and please tweet it if you like it. : )
Contents
Usage Examples
Use Case
Single-Handed Navigation
Digestible Unit of Information
Data
Quick Start
Configuration
Methods
Throwing Card Out of the Stack
Events
Event Object
Download
Browser Bundle
Dependencies
Usage Examples
Card stack.
Card stack using angular-swing module.
Card-stack using angular2-swing module.
Programmatically control the state of the card.
Indicate the state of the drop using throwConfidence and direction event object properties.
The code for all of the examples is in the ./examples/ folder.
Raise an issue if you are missing an example.
Use Case
A collection of observations about the extended use case of the swipeable cards interface, that I found useful when considering the implementation.
Single-Handed Navigation
Mobile devices are frequently used on-the-go, which drastically increases the probability that you'll attempt to navigate apps using just one hand, with the key digit being the mighty thumb.
Instead of browsing endless lists for the hidden perfect piece of data — be it the right music for the moment, what to do tonight, or your next potential hookup — card-swiping turns decision making into a highly engaging Choose-Your-Own-Adventure game.
[..] the "card" on a mobile device becomes more and more important as a digestible unit of information on a small screen for users who are on the go and mostly glancing through their apps before settling into the ones that truly engage them.
More than a scroll and perhaps even more than discrete taps themselves, cards create repetitive, deliberate, discrete decision moments over and over. And as the user swipes, you can learn.
The time they swipe, the speed they swipe, what they swiped, the geolocation where they swiped, and even how similar the results of that swipe are vs. a swipe earlier that session are all possibilities that are yielding smarter apps for you and me every day.
// Prepare the cards in the stack for iteration.
const cards = [].slice.call(document.querySelectorAll('ul li'));
// An instance of the Stack is used to attach event listeners.
const stack = Swing.Stack();
cards.forEach((targetElement) => {
// Add card element to the Stack.
stack.createCard(targetElement);
});
// Add event listener for when a card is thrown out of the stack.
stack.on('throwout', (event) => {
// e.target Reference to the element that has been thrown out of the stack.
// e.throwDirection Direction in which the element has been thrown (Direction.LEFT, Direction.RIGHT).
console.log('Card has been thrown out of the stack.');
console.log('Throw direction: ' + (event.throwDirection == Direction.LEFT ? 'left' : 'right'));
});
// Add event listener for when a card is thrown in the stack, including the spring back into place effect.
stack.on('throwin', () => {
console.log('Card has snapped back to the stack.');
});
Configuration
const config = {
/**
* Invoked in the event of dragmove.
* Returns a value between 0 and 1 indicating the completeness of the throw out condition.
* Ration of the absolute distance from the original card position and element width.
*
* @param {number} xOffset Distance from the dragStart.
* @param {number} yOffset Distance from the dragStart.
* @param {HTMLElement} element Element.
* @returns {number}
*/
throwOutConfidence: (xOffset, yOffset, element) => {
const xConfidence = Math.min(Math.abs(xOffset) / element.offsetWidth, 1);
const yConfidence = Math.min(Math.abs(yOffset) / element.offsetHeight, 1);
return Math.max(xConfidence, yConfidence);
}
};
const stack = stack = Swing.Stack(config);
Name
Description
Default
isThrowOut
Invoked in the event of dragend. Determines if element is being thrown out of the stack.
Element is considered to be thrown out when throwOutConfidence is equal to 1.
allowedDirections
Array of directions in which cards can be thrown out.
Invoked in the event of dragmove. Returns a value between 0 and 1 indicating the completeness of the throw out condition.
Ration of the absolute distance from the original card position and element width.
throwOutDistance
Invoked when card is added to the stack. The card is thrown to this offset from the stack.
The value is a random number between minThrowOutDistance and maxThrowOutDistance.
minThrowOutDistance
In effect when throwOutDistance is not overwritten.
450.
maxThrowOutDistance
In effect when throwOutDistance is not overwritten.
500.
rotation
Invoked in the event of dragmove. Determine the rotation of the element.
Rotation is equal to the proportion of horizontal and vertical offset times the maximumRotation constant.
maxRotation
In effect when rotation is not overwritten.
20.
transform
Invoked in the event of dragmove and every time the physics solver is triggered.
Uses CSS transform to translate element position and rotation.
allowMovement
Function that determines if movement is allowed when a movement event is fired. It has two arguments, the event object and a boolean set to true if on a touch device.
A function that returns true for all movement events.
All of the configuration parameters are optional. Refer to the source code of the card module to learn the parameters associated with every callback.
Creates an instance of Card and associates it with the element. If prepend is true, the card is prepended to the stack, instead of appended [default: false].
stack.getCard(element)
Returns card associated with an element.
stack.on(event, listener)
Attaches an event listener.
card.on(event, listener)
Attaches an event listener.
card.throwIn(coordinateX, coordinateY)
Throws a card into the stack from an arbitrary position. coordinateX, coordinateY is the position at the start of the throw.
card.throwOut(coordinateX, coordinateY)
Throws a card out of the stack in the direction away from the original offset. coordinateX, coordinateY is the position at the start of the throw.
card.destroy()
Unbinds all Hammer.Manager events. Removes the listeners from the physics simulation.
Throwing Card Out of the Stack
Use the card.throwOut(coordinateX, coordinateY) method to throw the card out of the stack. Offset the position to whatever direction you want to throw the card, e.g.
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/gajus/swing là nguồn chính thức.
gajus/swing có bao nhiêu sao?
gajus/swing có 2.6k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/gajus/swing. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
gajus/swing có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho gajus/swing. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
gajus/swing còn đang phát triển không?
Commit gần nhất trên gajus/swing là 3.2 năm trước (theo timestamp GitHub). Repo có 246 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
gajus/swing là gì?
gajus/swing (gajus/swing) là dự án JavaScript trên GitHub. Theo mô tả gốc: A swipeable cards interface. The swipe-left/swipe-right for yes/no input. As seen in apps like Jelly and Tinder.
gajus/swing viết bằng ngôn ngữ gì?
gajus/swing 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.
Muốn nghe thêm một ý kiến về swing?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về swing.