forked from zmmbreeze/lining.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
420 lines (398 loc) · 18.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lining.js</title>
<meta name="Keywords" content="lining.js,typography,line,javascript,css">
<meta name="Description" content="An easy to use javascript plugin offers you complete DOWN-TO-THE-LINE control for radical web typography.">
<link rel="shortcut icon" href="assets/favicon.ico" type="image/x-icon">
<link rel="icon" href="assets/favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon" href="assets/lining_icon_76.png">
<link rel="apple-touch-icon" sizes="76x76" href="assets/lining_icon_76.png">
<link rel="apple-touch-icon" sizes="120x120" href="assets/lining_icon_76@2x.png">
<link rel="apple-touch-icon" sizes="152x152" href="assets/lining_icon_76@2x.png">
<link href='http://fonts.googleapis.com/css?family=Roboto+Slab|Calligraffitti|Inconsolata|Dancing+Script|Handlee|Droid+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="assets/normalize.css">
<link rel="stylesheet" href="assets/index.css">
<link rel="stylesheet" href="assets/prism.css">
<script src="build/lining.min.js"></script>
<script src="build/lining.effect.min.js"></script>
</head>
<body>
<a href="https://github.com/zmmbreeze/lining.js" target="_blank"><img style="position:fixed;top:0;right:0;z-index:999;border:0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
<div class="main">
<div class="center">
<div class="v-center">
<h1>
<img src="assets/lining_icon_web.png" alt="lining.js icon" width="120" height="120">
<em class="em-red">lin</em><em class="em-green">ing</em>.js
</h1>
<p>In CSS we already have the selector <code>::first-line</code> to apply style on the first line of element. But there is no selector like <code>::nth-line()</code>, <code>::nth-last-line()</code> or even <code>::last-line</code>. Then I read an article <a href="http://css-tricks.com/a-call-for-nth-everything/" target="_blank">A Call for ::nth-everything</a> from CSS tricks. <code>::nth-line()</code> is actually really useful in some situation.</p>
<p>There comes <strong><a href="https://github.com/zmmbreeze/lining.js" target="_blank">Lining.js</a></strong>. It offers you complete <strong>down-to-the-line</strong> control like this:</p>
<pre><code class="language-markup"><div class="poem" data-lining>Some text...</div>
<style>
.poem .line[first] { /* `.poem::first-line`*/ }
.poem .line[last] { /* `.poem::last-line` */ }
.poem .line[index="5"] { /* `.poem::nth-line(5)` */ }
.poem .line:nth-of-type(-n+2) { /* `.poem::nth-line(-n+2)` */ }
.poem .line:nth-last-of-type(2n) { /* `.poem:::nth-last-line(2n)` */ }
</style>
<script src="YOUR_PATH/lining.min.js"></script>
</code></pre>
<p>Supported browsers
<img src="assets/chrome_256x256.png" width="24" height="24" alt="Lastest Chrome" title="Latest Chrome">
<img src="assets/firefox_256x256.png" width="24" height="24" alt="Lastest Firefox" title="Latest Firefox">
<img src="assets/safari_256x256.png" width="24" height="24" alt="Lastest Safari" title="Latest Safari">
<img src="assets/safari-ios_256x256.png" width="24" height="24" alt="Lastest Mobile Safari" title="Lastest Mobile Safari">
<img src="assets/opera_256x256.png" width="24" height="24" alt="Lastest Opera" title="Lastest Opera">
</p>
</div>
<a href="#demo-1" class="tip">DEMO</a>
</div>
</div>
<div class="demo demo-1" id="demo-1">
<div class="center">
<div class="v-center">
<div data-lining class="poem preview">
As soon as wolf began to feel that he would like a decent meal, He went and knocked on Grandma's door.<br/> When Grandma opened it, she saw<br/> The sharp white teeth, the horrid grin,<br/> And Wolfie said, 'May I come in?'<br/> Poor Grandmamma was terrified,<br/> 'He's going to eat me up!' she cried.
</div>
<div class="code">
<pre><code class="language-css">.poem {
line-height: 40px;
font-size: 32px;
font-family: 'Dancing Script' serif;
}
.poem .line:nth-of-type(-n+2) {
font-size: 42px;
color: #DA4453;
}</code></pre>
</div>
</div>
<a class="switcher" data-do="toggle" data-status="0" href="###">SHOW CODE</a>
<a href="#demo-2" class="tip">NEXT</a>
</div>
</div>
<div class="demo demo-2" id="demo-2">
<div class="center">
<div class="v-center">
<div data-lining class="fadeout preview">
If you want to view paradise<br/>
Simply look around and view it<br/>
Anything you want to, do it<br/>
Want to change the world,<br/>
there's nothing to it<br/>
There is no life I know<br/>
To compare with<br/>
pure imagination
</div>
<div class="code">
<pre><code class="language-css">.fadeout {
font-size: 36px;
line-height: 36px;
color: hsla(354, 67%, 46%, 1);
font-family: 'Handlee' serif;
}
.fadeout .line:nth-last-of-type(3) {
color: hsla(354, 67%, 55%, 1);
font-size: 80%;
}
.fadeout .line:nth-last-of-type(2) {
color: hsla(354, 67%, 60%, 1);
font-size: 70%;
}
.fadeout .line:nth-last-of-type(1) {
color: hsla(354, 67%, 65%, 1);
font-size: 60%
}</code></pre>
</div>
</div>
<a class="switcher" data-do="toggle" data-status="0" href="###">SHOW CODE</a>
<a href="#demo-3" class="tip">NEXT</a>
</div>
</div>
<div class="demo demo-3" id="demo-3">
<div class="center">
<div class="v-center">
<div data-lining class="linenumber preview">
<h3>What is typography</h3>
<p>Typography (from the Greek words τύπος typos "form" and γράφειν graphein "to write") is the art and technique of arranging type to make written language most appealing to learning and recognition. The arrangement of type involves selecting typefaces, point size, line length, line-spacing (leading), letter-spacing (tracking), and adjusting the space within letters pairs (kerning[2]). Type design is a closely related craft, sometimes considered part of typography; most typographers do not design typefaces, and some type designers do not consider themselves typographers. In modern times, typography has been put in film, television and online broadcasts to add emotion to communication.<br/>
From <a href="http://en.wikipedia.org/wiki/Typography" target="_blank">Wikipedia</a>.</P>
</div>
<div class="code">
<pre><code class="language-css">.linenumber .line {
position: relative;
margin-left: 32px; /* 16 * 2*/
}
.linenumber .line:before {
content: attr(index) '.';
position: absolute;
right: 10px;
margin-right: 100%;
width: 1em;
font-size: 16px;
text-align: center;
color: #999;
}</code></pre>
</div>
</div>
<a class="switcher" data-do="toggle" data-status="0" href="###">SHOW CODE</a>
<a href="#demo-4" class="tip">NEXT</a>
</div>
</div>
<div class="demo demo-4" id="demo-4">
<div class="center">
<div class="v-center">
<div class="vtxt preview" data-lining>
桃花庵歌 <small>唐寅</small><br/>
桃花塢裡桃花庵,桃花庵下桃花仙。<br/>
桃花仙人種桃樹,又摘桃花換酒錢。<br/>
酒醒只在花前坐,酒醉還來花下眠。<br/>
半醉半醒日復日,花落花開年復年。<br/>
但願老死花酒間,不願鞠躬車馬前。<br/>
車塵馬足顯者事,酒盞花枝隱士緣。<br/>
若將顯者比隱士,一在平地一在天。<br/>
若將花酒比車馬,彼何碌碌我何閒。<br/>
別人笑我太瘋癲,我笑他人看不穿。<br/>
不見五陵豪傑墓,無花無酒鋤作田。<br/>
</div>
<div class="code">
<pre class="language-css"><code class="language-css">.vtxt {
font-size: 24px;
color: #333;
-webkit-writing-mode: vertical-rl;
writing-mode: vertical-rl;
}
.vtxt .line:first-of-type {
font-size: 1.5em;
color: #D0496A;
}
.vtxt .line:first-of-type small {
color: #333;
font-size: .6666666em;
}
</code></pre>
</div>
</div>
<a class="switcher" data-do="toggle" data-status="0" href="###">SHOW CODE</a>
<a href="#demo-5" class="tip">NEXT</a>
</div>
</div>
<div class="demo demo-5" id="demo-5">
<div class="center">
<div class="v-center">
<div class="effects preview">
<div id="effectText" class="effects-text">
<h3>The Furthest Distance In The World</h3>
<h4>by Rabindranath Tagore</h4>
<p>The furthest distance in the world<br/>
Is not between life and death<br/>
But when I stand in front of you<br/>
Yet you don't know that I love you.</p>
<p>The furthest distance in the world<br/>
Is not when I stand in front of you<br/>
Yet you can't see my love<br/>
But when undoubtly knowing the love from both<br/>
Yet cannot be together.</p>
<p>The furthest distance in the world<br/>
Is not being apart while being in love<br/>
But when I plainly cannot resist the yearning<br/>
Yet pretending you have never been in my heart.</p>
<p>The furthest distance in the world<br/>
Is not struggling against the tides<br/>
But using one's indifferent heart<br/>
To dig an uncrossable river<br/>
For the one who loves you.</p>
</div>
<div class="effects-do">
<label>
<select id="effectName">
<option value="fadeIn">fadeIn</option>
<option value="slideIn">slideIn</option>
<option value="slideInFromLeft">slideInFromLeft</option>
<option value="slideInFromRight">slideInFromRight</option>
<option value="rolling">rolling</option>
</select>
</label>
<button data-do="run-effect">GO!</button>
</div>
<a class="switcher" data-do="show-code" href="###">SHOW CODE</a>
</div>
<div class="code">
<pre class="language-markup"><code class="language-markup"><script src="YOUR_PATH/lining.min.js"></script>
<script src="YOUR_PATH/lining.effect.min.js"></script>
<div data-lining data-effect="rolling">
Your text...
<div></code></pre>
<a class="switcher" data-do="preview" href="###">PREVIEW</a>
</div>
</div>
<a href="#usage" class="tip">USAGE</a>
</div>
</div>
<div class="main usage" id="usage">
<div class="center">
<h2>BASIC USAGE</h2>
<p>All you need to do is adding <code>data-lining</code> attribute on your block element and including the <code>lining.min.js</code> script. Then you can write css to control it's line style. For example:</p>
<pre><code class="language-markup"><div class="poem" data-lining>Some text...</div>
<style>
.poem { /* default style for `.poem` */ }
.nolining .poem { /* style for `.poem` when browser don't support lining.js */ }
.poem[data-lining] { /* style for `.poem` when browser support lining.js */ }
.poem[data-lining="end"] { /* style for `.poem` when `text-line` tags created */ }
.poem .line { /* style for lines */ }
</style>
<script src="YOUR_PATH/lining.min.js"></script>
</code></pre>
<h2>RWD</h2>
<p>If you want your line style support Responsive web design. Make sure you add the <code>data-auto-resize</code> attribute. It will automatically relining when window resize event happen.</p>
<pre><code class="language-markup"><div class="poem" data-lining data-auto-resize>Some text...</div></code></pre>
<h2>Other attributes</h2>
<p><code>data-from</code> and <code>data-to</code> help you control which line tags to be created. For example:</p>
<pre><code class="language-markup"><div class="poem"
data-lining
data-from="2"
data-to="3">
First Line.<br/>
Second Line.<br/>
Third Line.<br/>
Fourth Line.<br/>
</div>
</code></pre>
<p>After lining, only the second and third line tag will be created. Check out the <a href="http://jsbin.com/riweb/2/edit?output" target="_blank">demo</a>.</p>
<p>And <code>data-line-class</code> help you control the class name of line tags, if you don't want to use the default class name: <code>line</code>.</p>
<h2>Javascript</h2>
<p>You can also create and manage line tags by javascript. And give you four events to do special things.</p>
<pre><code class="language-markup"><div id="poem">Some text..</div>
<script>
var poem = document.getElementById('poem');
lining.util.on(poem, 'beforelining', function (e) {
// prevent lining if you want
e.preventDefault();
}, false);
lining.util.on(poem, 'afterlining', function () {
// do something after lining
}, false);
lining.util.on(poem, 'beforeunlining', function () {
// do something before unlining
// can't prevent unlining
}, false);
lining.util.on(poem, 'afterunlining', function () {
// do something after unlining
}, false);
// start lining
var poemLining = lining(poem, {
// optional config
'autoResize': true,
'from': 2,
'to': 3,
'lineClass': 'my-class'
});
// `unlining` method will remove all line tags.
poemLining.unlining();
// `relining` method will call `unlining` first if needed,
// then start lining again.
poemLining.relining();
</script>
</code></pre>
<h2>lining.effect.js</h2>
<p><code>lining.effect.js</code> is an extra part of <code>lining.js</code>. It gives you the power to add appearances animation on your lines. Use it like this:</p>
<pre><code class="language-markup"><script src="YOUR_PATH/lining.min.js"></script>
<script src="YOUR_PATH/lining.effect.min.js"></script>
<div data-lining data-effect="rolling">
Your text...
<div></code></pre>
<div class="install">
<a href="https://github.com/zmmbreeze/lining.js/releases" target="_blank" class="download">DOWNLOAD</a>
or
<code class="bower"><span>$</span> bower install lining.js</code><br/>
or using CDN provided by <a href="http://www.jsdelivr.com/" target="_blank">jsDelivr</a><br/>
<pre class="cdn"><code class="language-markup"><script src="//cdn.jsdelivr.net/lining.js/0.3.2/lining.min.js"></script></code></pre>
</div>
<p class="share-info">
<a href="https://twitter.com/share" class="twitter-share-button" data-text="An easy to use javascript plugin offers you complete DOWN-TO-THE-LINE control for radical web typography." data-size="large" data-hashtags="liningjs">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<a href="https://twitter.com/zhoumm" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @zhoumm</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</p>
</div>
</div>
<a href="###" data-do="top" class="top"></a>
<script>
// set style for body
document.body.style.height = document.documentElement.clientHeight + 'px';
lining.util.on(window, 'resize', function () {
document.body.style.height = document.documentElement.clientHeight + 'px';
});
</script>
<script src="assets/prism.js"></script>
<script>
var g = function (id) {
return document.getElementById(id);
};
// -------------------------
// actions
// -------------------------
var effectLining;
var actions = {
'toggle': function (target) {
var status = target.getAttribute('data-status');
var prev = target.previousElementSibling;
if (status === '1') {
// show preview
prev.removeAttribute('show-code');
target.setAttribute('data-status', '0');
target.innerHTML = 'SHOW CODE';
}
else {
// show code
prev.setAttribute('show-code', '');
target.setAttribute('data-status', '1');
target.innerHTML = 'PREVIEW';
}
},
'preview': function (target) {
target.parentNode.parentNode.removeAttribute('show-code');
},
'show-code': function (target) {
target.parentNode.parentNode.setAttribute('show-code', '');
},
'top': function () {
if (window.scrollTo) {
window.scrollTo(0, 0);
}
},
'run-effect': function (target) {
var effectName = g('effectName').value;
var effectText = g('effectText');
effectText.setAttribute('data-effect', effectName);
if (!effectLining) {
effectLining = lining(effectText);
}
else {
effectLining.relining(true);
}
}
};
lining.util.on(window, 'load', function () {
lining.util.on(document.body, 'click', function (e) {
var target = e.target;
var actionName = target.getAttribute('data-do');
if (!actionName) {
return;
}
e.preventDefault();
actions[actionName](target);
}, false);
});
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36422454-1', 'auto');
ga('send', 'pageview');
</script>
</div>
</body>
</html>