Widow Adjust

讨厌网站上的排版“孤行(widows)”?用这个吧。请参见 artequalswork.com 上的实际应用。「Hate typographic widows hanging around on your site? Use this. See it in action on artequalswork.com」

  • 所有者: nathanford/widowadjust
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Widow Adjust

…is a Javascript to automatically fix typographic widows on your web pages. It is designed to work with responsive sites, fixing widows as it finds them on resize or orientation change.

What is a Widow?

Widows are left over characters at the end of a paragraph. If the last line of a paragraph contains less than 14 characters (for example), it is said to have a widow. Widows are disruptive to both text layouts and reading experiences. Therefore, we must tame them.

How does Widow Adjust work?

By setting the elements you want fixed, the number of characters you consider a “widow”, and the method by which you want them fixed, you can eliminate widows from your site. The script will cycle through the elements, apply your “method” (more on that later), check if the widow has been fixed, and repeat until the widow is tamed.

You only need to download the script, and link it in the HEAD of your page(s). Then, you can call a simple Javascript function to start taming widows:

wt.fix();

You can also set a few custom options:

Option Description Default

elements Which elements? jQuery-like Selector 'p,li,dd'

chars Number of characters to qualify a “widow” 14

method Method by which to fix the widow 'word-spacing'
Options: 'word-spacing'
'padding-right/padding-left'
'letter-spacing'
'nbsp'

dir Used with certain methods. +/- change 'pos'
Options: 'pos'
'neg'

event Any window events on which to run the fix 'orientationchange'
Suggested Options: 'orientationchange'
'resize'

The script will run initially on window.onload, and then fire every time the 'event' is triggered.

Example Implementation

You can run multiple instances of the function target different elements with different methods. For example, here we are adding padding to the right of paragraphs in our main post article:

wt.fix({
elements: '#posts article p',
chars: 20,
method: 'padding-right',
event: 'resize'
});

And on the same page, on the same events, we may want to fix the headers in our footer by adding non-breaking spaces:

wt.fix({
elements: 'footer aside h1',
chars: 20,
method: 'nbsp',
event: 'resize'
});

Browser Support

Widow Adjust works in IE8+ and all other modern browsers.

Details

Widow Adjust was created by Nathan Ford. Feel free to interrupt him any time with questions, concerns, complaints, etc.

nathan@artequalswork.com
@nathan_ford on Twitter

主要指標

概覽
名稱與所有者nathanford/widowadjust
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2012-06-21 11:29:05
推送於2019-11-02 22:52:35
最后一次提交2019-11-02 17:52:35
發布數0
用户参与
星數348
關注者數18
派生數27
提交數9
已啟用問題?
問題數4
打開的問題數3
拉請求數0
打開的拉請求數2
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?