Điểm qua adobe/balance-text: 1.4k sao trên GitHub, viết chủ yếu bằng JavaScript. A plugin for implementing balancing of wrapping text in a web page
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 utility to provide an alternate text wrapping algorithm. I hope to get this into the CSS spec, so it's implemented as an optional "polyfill". It already appears in the CSS Text Module Level 4 Editor's Draft.
The default text rendering algorithm is:
Add 1 word at a time to the current line until the next word won't fit.
Break text so that the next word starts on a new line.
Repeat until all text has been rendered.
That algorithm guarantees that the text is rendered using the least number of lines, but when text is centered and wraps to more than 1 line, it can produce visually undesirable results such as a long line of centered text followed by a short line of centered text. What I want is for the text to be balanced across lines. By "balanced across lines", I mean that the text is rendered so that the amount of text on each line is about the same. This plugin implements a line-breaking algorithm to do that automatically.
How it works
Here is a simple Balance Text setup:
<style type="text/css">
/* Plugin looks for elements with class named "balance-text" */
.balance-text {
text-wrap: balance; /* Apply (proposed) CSS style */
}
</style>
<script src="balancetext.min.js"></script>
<script>
balanceText();
</script>
See the demo provided or this online version for a working sample.
If you call balanceText(), Balance Text will automatically run on any elements with balance-text class:
when the page loads (DOM Ready event)
when it is resized
You may also manually trigger it, e.g. if you're dynamically adding text to the DOM:
balanceText(el); // Balance a single element
balanceText([el, el]); // Balance a list of elements
balanceText('.el'); // Balance a list of elements based on query selector
This will apply the balance-text formatting once. If you'd like to re-apply automatically during window resize, you can use pass an options parameter instead:
balanceText(el, {watch: true});
If you need to manually re-balance all triggered elements, use:
balanceText.updateWatched();
How to use with jQuery
This library used to be implemented as a jQuery plugin (as of v2.0.0) but was re-written as a native utility (as of 3.0.0). If you'd like to continue using the jQuery interface, you can continue using 2.0.0 (link below).
You can also migrate to balanceText() from jQuery using this guide (shown compared to the 2.0.0 interface):
// Put the balanceText utility into "polyfill" mode
// This was the default mode of the 2.0.0 jQuery plugin when it loaded
$.ready(function() {
balanceText();
});
// manually trigger on a list of elements
balanceText($('.my-class')); // equivalent to $('.my-class').balanceText();
// manually trigger on a list of elements and update on browser resize
balanceText($('.my-class'), {watch: true}); // equivalent to $.balanceText('.my-class');
// manually re-balance all triggered elements
balanceText.updateWatched(); // equivalent to $.fn.balanceTextUpdate();
adobe/balance-text có 1.4k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/adobe/balance-text. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
adobe/balance-text có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho adobe/balance-text. 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.
adobe/balance-text còn đang phát triển không?
Commit gần nhất trên adobe/balance-text là 2.6 năm trước (theo timestamp GitHub). Repo có 77 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
adobe/balance-text là gì?
adobe/balance-text (adobe/balance-text) là dự án JavaScript trên GitHub. Theo mô tả gốc: A plugin for implementing balancing of wrapping text in a web page
Đọc thêm về adobe/balance-text ở đâu?
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/adobe/balance-text là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về balance-text?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về balance-text.