TreeSaver 使用教程整理——Step 5: Adding Illustration Figures

请首先阅读前几篇教程,才能对本篇文章了解比较深入:

TreeSaver 使用教程整理——Step 1: Getting Started

TreeSaver 使用教程整理——Step 2: Adding Basic UI

TreeSaver 使用教程整理——Step 3: Creating Grids

TreeSaver 使用教程整理——Step 4: Using a Title Figure

我们在上一步的基础上,copy到 step5 作为我们 step5 初始的基础。

Step 5: Adding Illustration Figures

这步开始,我们需要用到的图片,演示的图片我们可以在 http://www.epathwaysdev.net/treesaver/img/ 获得。 这是爱丽丝梦境游记中的一些图。

这些图我们都将放在演示根目录的 img 目录下。

对演示正文 index.html 的修改

现在我们使用 Figures 来增加图片:

我们在文本的第二段增加如下代码:

<figure>

  <img data-sizes="single" src="../img/01-rabbit-280.jpg"

      width="280" height="429"

      alt="An illustration of a white rabbit Looking at a pocket watch">

</figure>

就像我们上一步,使用figure显示章节标题,我们现在使用figure显示插图。我们把data-sizes属性设置成single。 这意味着我们要把这个图作为单栏(single-column)来显示。这是因为我们图片的宽度是280px,它正好是单栏的宽度。

下面我们增加一个两栏宽的插图,并且一次增加两张图:

<figure>

  <img data-sizes="single" src="../img/02-alice-door-280.jpg"

      width="280" height="288"

      alt="An illustration of Alice looking at a small door behind a curtain">

  <img data-sizes="double" data-src="../img/02-alice-door-600.jpg"

      width="600" height="617"

      alt="An illustration of Alice looking at a small door behind a curtain">

</figure>

上面内容源文件中,我们增加了两个img标签,第一个img标签对应的图片是280 pixels,所以我们用的是单栏尺寸;第二个img标签对应的图片是600 pixels宽,所以我们使用两栏宽。

另外我们可以注意到img标签我们使用的是 data-src 属性,而不是 src 属性,这是为了防止非Treesaver浏览器下载两次图片。Treesaver 在处理显示时,将自动把 data-src 属性重命名成 src 。

完整的内容如下:

<!doctype html>

<html class="no-js no-treesaver">

  <head>

    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,minimum-scale=1,maximum-scale=1">

    <link rel="stylesheet" href="style.css">

    <link rel="resources" href="resources.html">

    <script src="../treesaver-0.9.2.js"></script>

    <title>Down the Rabbit-Hole - Alice&#8217;s Adventures in Wonderland</title> 

  </head>

  <body>

   

      <article> 

      <figure> 

        <h2 data-sizes="title fallback"> 

          Chapter I:          Down the Rabbit-Hole

        </h2> 

      </figure> 

      <p> 

      Alice was beginning to get very tired of sitting by her sister on the

      bank, and of having nothing to do: once or twice she had peeped into the

      book her sister was reading, but it had no pictures or conversations in

      it, &#8220;and what is the use of a book,&#8221; thought Alice &#8220;without pictures or

      conversation?&#8221;

      </p> 

      <p> 

      So she was considering in her own mind (as well as she could, for the

      hot day made her feel very sleepy and stupid), whether the pleasure

      of making a daisy-chain would be worth the trouble of getting up and

      picking the daisies, when suddenly a White Rabbit with pink eyes ran

      close by her.

      </p> 

      <figure> 

        <img data-sizes="single" src="../img/01-rabbit-280.jpg"

            width="280" height="429"

            alt="An illustration of a white rabbit Looking at a pocket watch"> 

      </figure> 

      <p> 

      There was nothing so <em>very</em> remarkable in that; nor did Alice think it so

      <em>very</em> much out of the way to hear the Rabbit say to itself, &#8220;Oh dear!

      Oh dear! I shall be late!&#8221; (when she thought it over afterwards, it

      occurred to her that she ought to have wondered at this, but at the time

      it all seemed quite natural); but when the Rabbit actually <em>took a watch

      out of its waistcoat-pocket</em>, and looked at it, and then hurried on,

      Alice started to her feet, for it flashed across her mind that she had

      never before seen a rabbit with either a waistcoat-pocket, or a watch

      to take out of it, and burning with curiosity, she ran across the field

      after it, and fortunately was just in time to see it pop down a large

      rabbit-hole under the hedge.

      </p> 

      <p> 

      In another moment down went Alice after it, never once considering how

      in the world she was to get out again.

      </p> 

      <p> 

      The rabbit-hole went straight on like a tunnel for some way, and then

      dipped suddenly down, so suddenly that Alice had not a moment to think

      about stopping herself before she found herself falling down a very deep

      well.

      </p> 

      <p> 

      Either the well was very deep, or she fell very slowly, for she had

      plenty of time as she went down to look about her and to wonder what was

      going to happen next. First, she tried to look down and make out what

      she was coming to, but it was too dark to see anything; then she

      looked at the sides of the well, and noticed that they were filled with

      cupboards and book-shelves; here and there she saw maps and pictures

      hung upon pegs. She took down a jar from one of the shelves as

      she passed; it was labelled &#8220;Orange Marmalade&#8221;, but to her great

      disappointment it was empty: she did not like to drop the jar for fear

      of killing somebody, so managed to put it into one of the cupboards as

      she fell past it.

      </p> 

      <p> 

      &#8220;Well!&#8221; thought Alice to herself, &#8220;after such a fall as this, I shall

      think nothing of tumbling down stairs! How brave they&#8217;ll all think me at

      home! Why, I wouldn&#8217;t say anything about it, even if I fell off the top

      of the house!&#8221; (Which was very likely true.)

      </p> 

      <p> 

      Down, down, down. Would the fall <em>never</em> come to an end! &#8220;I wonder how

      many miles I&#8217;ve fallen by this time?&#8221; she said aloud. &#8220;I must be getting

      somewhere near the centre of the earth. Let me see: that would be four

      thousand miles down, I think&mdash;&#8221; (for, you see, Alice had learnt several

      things of this sort in her lessons in the schoolroom, and though this

      was not a <em>very</em> good opportunity for showing off her knowledge, as there

      was no one to listen to her, still it was good practice to say it over)

      &#8220;&mdash;yes, that&#8217;s about the right distance&mdash;but then I wonder what Latitude

      or Longitude I&#8217;ve got to?&#8221; (Alice had no idea what Latitude was, or

      Longitude either, but thought they were nice grand words to say.)

      </p> 

      <p> 

      Presently she began again. &#8220;I wonder if I shall fall right <em>through</em> the

      earth! How funny it&#8217;ll seem to come out among the people that walk with

      their heads downward! The Antipathies, I think&mdash;&#8221; (she was rather glad

      there WAS no one listening, this time, as it didn&#8217;t sound at all the

      right word) &#8220;&mdash;but I shall have to ask them what the name of the country

      is, you know. Please, Ma&#8217;am, is this New Zealand or Australia?&#8221; (and

      she tried to curtsey as she spoke&mdash;fancy <em>curtseying</em> as you&#8217;re falling

      through the air! Do you think you could manage it?) &#8220;And what an

      ignorant little girl she&#8217;ll think me for asking! No, it&#8217;ll never do to

      ask: perhaps I shall see it written up somewhere.&#8221;

      </p> 

      <p> 

      Down, down, down. There was nothing else to do, so Alice soon began

      talking again. &#8220;Dinah&#8217;ll miss me very much to-night, I should think!&#8217;

      (Dinah was the cat.) &#8220;I hope they&#8217;ll remember her saucer of milk at

      tea-time. Dinah my dear! I wish you were down here with me! There are no

      mice in the air, I&#8217;m afraid, but you might catch a bat, and that&#8217;s very

      like a mouse, you know. But do cats eat bats, I wonder?&#8221; And here Alice

      began to get rather sleepy, and went on saying to herself, in a dreamy

      sort of way, &#8220;Do cats eat bats? Do cats eat bats?&#8221; and sometimes, &#8220;Do

      bats eat cats?&#8221; for, you see, as she couldn&#8217;t answer either question,

      it didn&#8217;t much matter which way she put it. She felt that she was dozing

      off, and had just begun to dream that she was walking hand in hand with

      Dinah, and saying to her very earnestly, &#8220;Now, Dinah, tell me the truth:

      did you ever eat a bat?&#8221; when suddenly, thump! thump! down she came upon

      a heap of sticks and dry leaves, and the fall was over.

      </p> 

      <p> 

      Alice was not a bit hurt, and she jumped up on to her feet in a moment:

      she looked up, but it was all dark overhead; before her was another

      long passage, and the White Rabbit was still in sight, hurrying down it.

      There was not a moment to be lost: away went Alice like the wind, and

      was just in time to hear it say, as it turned a corner, &#8220;Oh my ears

      and whiskers, how late it&#8217;s getting!&#8221; She was close behind it when she

      turned the corner, but the Rabbit was no longer to be seen: she found

      herself in a long, low hall, which was lit up by a row of lamps hanging

      from the roof.

      </p> 

      <p> 

      There were doors all round the hall, but they were all locked; and when

      Alice had been all the way down one side and up the other, trying every

      door, she walked sadly down the middle, wondering how she was ever to

      get out again.

      </p> 

      <figure> 

        <img data-sizes="single" src="../img/02-alice-door-280.jpg"

            width="280" height="288"

            alt="An illustration of Alice looking at a small door behind a curtain"> 

        <img data-sizes="double" data-src="../img/02-alice-door-600.jpg"

            width="600" height="617"

            alt="An illustration of Alice looking at a small door behind a curtain"> 

      </figure> 

      <p> 

      Suddenly she came upon a little three-legged table, all made of solid

      glass; there was nothing on it except a tiny golden key, and Alice&#8217;s

      first thought was that it might belong to one of the doors of the hall;

      but, alas! either the locks were too large, or the key was too small,

      but at any rate it would not open any of them. However, on the second

      time round, she came upon a low curtain she had not noticed before, and

      behind it was a little door about fifteen inches high: she tried the

      little golden key in the lock, and to her great delight it fitted!

      </p> 

      <p> 

      Alice opened the door and found that it led into a small passage, not

      much larger than a rat-hole: she knelt down and looked along the passage

      into the loveliest garden you ever saw. How she longed to get out of

      that dark hall, and wander about among those beds of bright flowers and

      those cool fountains, but she could not even get her head through the

      doorway; &#8220;and even if my head would go through,&#8221; thought poor Alice, &#8220;it

      would be of very little use without my shoulders. Oh, how I wish I could

      shut up like a telescope! I think I could, if I only know how to begin.&#8221;

      For, you see, so many out-of-the-way things had happened lately,

      that Alice had begun to think that very few things indeed were really

      impossible.

      </p> 

      <figure> 

        <img data-sizes="single" src="../img/03-alice-bottle-280.jpg"

            width="280" height="399"

            alt="An illustration of Alice witha small bottle"> 

      </figure> 

      <p> 

      There seemed to be no use in waiting by the little door, so she went

      back to the table, half hoping she might find another key on it, or at

      any rate a book of rules for shutting people up like telescopes: this

      time she found a little bottle on it, (&#8220;which certainly was not here

      before,&#8221; said Alice,) and round the neck of the bottle was a paper

      label, with the words &#8220;Drink Me&#8221; beautifully printed on it in large

      letters.

      </p> 

      <p> 

      It was all very well to say &#8220;Drink me,&#8221; but the wise little Alice was

      not going to do <em>that</em> in a hurry. &#8220;No, I&#8217;ll look first,&#8221; she said, &#8220;and

      see whether it&#8217;s marked "poison" or not&#8221; for she had read several nice

      little histories about children who had got burnt, and eaten up by wild

      beasts and other unpleasant things, all because they <em>would</em> not remember

      the simple rules their friends had taught them: such as, that a red-hot

      poker will burn you if you hold it too long; and that if you cut your

      finger <em>very</em> deeply with a knife, it usually bleeds; and she had never

      forgotten that, if you drink much from a bottle marked &#8220;poison,&#8221; it is

      almost certain to disagree with you, sooner or later.

      </p> 

      <p> 

      However, this bottle was <em>not</em> marked &#8220;poison,&#8221; so Alice ventured to taste

      it, and finding it very nice, (it had, in fact, a sort of mixed flavour

      of cherry-tart, custard, pine-apple, roast turkey, toffee, and hot

      buttered toast,) she very soon finished it off.

      </p> 

      <hr /> 

      <p> 

      &#8220;What a curious feeling!&#8221; said Alice; &#8220;I must be shutting up like a

      telescope.&#8221;

      </p> 

      <p> 

      And so it was indeed: she was now only ten inches high, and her face

      brightened up at the thought that she was now the right size for going

      through the little door into that lovely garden. First, however, she

      waited for a few minutes to see if she was going to shrink any further:

      she felt a little nervous about this; &#8220;for it might end, you know,&#8221; said

      Alice to herself, &#8220;in my going out altogether, like a candle. I wonder

      what I should be like then?&#8221; And she tried to fancy what the flame of a

      candle is like after the candle is blown out, for she could not remember

      ever having seen such a thing.

      </p> 

      <p> 

      After a while, finding that nothing more happened, she decided on going

      into the garden at once; but, alas for poor Alice! when she got to the

      door, she found she had forgotten the little golden key, and when she

      went back to the table for it, she found she could not possibly reach

      it: she could see it quite plainly through the glass, and she tried her

      best to climb up one of the legs of the table, but it was too slippery;

      and when she had tired herself out with trying, the poor little thing

      sat down and cried.

      </p> 

      <p> 

      &#8220;Come, there&#8217;s no use in crying like that!&#8221; said Alice to herself,

      rather sharply; &#8220;I advise you to leave off this minute!&#8221; She generally

      gave herself very good advice, (though she very seldom followed it),

      and sometimes she scolded herself so severely as to bring tears into

      her eyes; and once she remembered trying to box her own ears for having

      cheated herself in a game of croquet she was playing against herself,

      for this curious child was very fond of pretending to be two people.

      &#8220;But it&#8217;s no use now,&#8221; thought poor Alice, &#8220;to pretend to be two people!

      Why, there&#8217;s hardly enough of me left to make <em>one</em> respectable person!&#8221;

      </p> 

      <p> 

      Soon her eye fell on a little glass box that was lying under the table:

      she opened it, and found in it a very small cake, on which the words

      &#8220;Eat Me&#8221; were beautifully marked in currants. &#8220;Well, I&#8217;ll eat it,&#8221; said

      Alice, &#8220;and if it makes me grow larger, I can reach the key; and if it

      makes me grow smaller, I can creep under the door; so either way I&#8217;ll

      get into the garden, and I don&#8217;t care which happens!&#8221;

      </p> 

      <p> 

      She ate a little bit, and said anxiously to herself, &#8220;Which way? Which

      way?&#8221;, holding her hand on the top of her head to feel which way it was

      growing, and she was quite surprised to find that she remained the same

      size: to be sure, this generally happens when one eats cake, but Alice

      had got so much into the way of expecting nothing but out-of-the-way

      things to happen, that it seemed quite dull and stupid for life to go on

      in the common way.

      </p> 

      <p> 

      So she set to work, and very soon finished off the cake.

      </p> 

    </article> 

   

  </body>

</html>

 

资源文件的修改:

我们把资源文章中的如下部分修改;

<div class="grid">

  <div class="container" data-sizes="title"></div>

  <div class="column"></div>

</div>

<div class="grid cols-2">

  <div class="container cols-2" data-sizes="title"></div>

  <div class="column"></div>

  <div class="column col-2"></div>

</div>

<div class="grid cols-3">

  <div class="container cols-3" data-sizes="title"></div>

  <div class="column"></div>

  <div class="column col-2"></div>

  <div class="column col-3"></div>

</div>

修改为:

<div class="grid">

  <div class="container" data-sizes="title single"></div>

  <div class="column"></div>

</div>

<div class="grid cols-2">

  <div class="container cols-2" data-sizes="title double"></div>

  <div class="column"></div>

  <div class="container col-2" data-sizes="single"></div>

  <div class="column col-2"></div>

</div>

<div class="grid cols-3">

  <div class="container cols-3" data-sizes="title"></div>

  <div class="column"></div>

  <div class="container col-2 cols-2" data-sizes="double"></div>

  <div class="column col-2"></div>

  <div class="container col-3" data-sizes="single"></div>

  <div class="column col-3"></div>

</div>

 

第一栏: 我们对data-sizes 属性值增加的 single 值,标识我们在这里显示的图片最宽就是1栏。

这一步的实际演示效果如下:

image

第二栏:首先看演示效果:

最乐观效果,我们实现一个图跨两栏。当分栏的区域小到一定程度时, 我们则会用小图。

 image

image

 

当区域小到一定程度时,这里就会自动显示小图。

image 

所以我们在模板配置这里,配置了 double 和 single 两种情况。

Similarly, in our two-column grid we can reuse the container, adding double to the data-sizes attribute. However, we still need a container for single-column images. We do so by adding a second <div class="container"> into our markup. But instead of inserting the element into the beginning of the Grid, we insert it just before the final column. We do this because Treesaver automatically adjusts the size of any Column that appears after the Container. The first container is two-columns wide, so both columns appear after it in the markup; since the second container is only one-column wide (and in the second column), it appears only before the final column.

第三栏时

We do not reuse the title container in the three-column grid, instead we create two new Containers: one for single and the other for double. As with the previous grid, we make sure that the order of containers and columns in the markup gives us the correct column sizing (see the documentation on Containers for a detailed explanation here).

 

整个内容我们可以从下面地址获得:

http://www.epathwaysdev.net/treesaver/step6/01-down-the-rabbit-hole.html
不过这是第6步的内容,我们只需要简单的把第六步增加的调整取消即可。

参考资料:

https://github.com/Treesaver/treesaver/wiki/Walkthrough

你可能感兴趣的:(figure)