Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
565 lines (405 sloc) 28.9 KB
<!doctype html>
Welcome to the light side of the source, young padawan.
One step closer to learn something interesting you are...
_.' : `._
.-.'`. ; .'`.-.
__ / : ___\ ; /___ ; \ __
,'_ ""=-.:__;".-.";: :".-.":__;.-="" _`,
:' `.t""=-.. '<@.`;_ ',@:` ..-=""j.' `;
`:-.._J '-.-'L__ `-.-' L_..-;'
"-.__ ; .-" "-. : __.-"
L ' /.======.\ ' J
"-. "__" .-"
.-j/'.; ;"""" / .'\"-.
.' /:`. "-.: .-" .'; `.
.-" / ; "-. "-..-" .-" : "-.
.+"-. : : "-.__.-" ;-._ \
; \ `.; ; : : "+. ;
: ; ; ; : ; : \:
; : ; : ;: ; :
: \ ; : ; : ; / ::
; ; : ; : ; : ;:
: : ; : ; : : ; : ;
;\ : ; : ; ; ; ;
: `."-; : ; : ; / ;
; -: ; : ; : .-" :
:\ \ : ; : \.-" :
;`. \ ; : ;.'_..-= / ;
: "-. "-: ; :/." .' :
\ \ : ;/ __ :
\ .-`.\ /t-"" ":-+. :
`. .-" `l __/ /`. : ; ; \ ;
\ .-" .-"-.-" .' .'j \ / ;/
\ / .-" /. .'.' ;_:' ;
:-""-.`./-.' / `.___.'
\ `t ._ /
So you'd like to know how to use impress.js?
You've made the first, very important step - you're reading the source code.
And that's how impress.js presentations are built - with HTML and CSS code.
Believe me, you need quite decent HTML and CSS skills to be able to use impress.js effectively.
And what is even more important, you need to be a designer, too, because there are no default
styles for impress.js presentations, there is no default or automatic layout for them.
You need to design and build it by hand.
Would you still like to know how to use impress.js?
那么你想知道,怎么去使用 impress.js吗?
更重要的是,你需要会一些设计,因为impress.js没有提供默认的格式和效果。(twitter Bootstrap泪目……)
<html lang="en">
<meta charset="utf-8" />
<meta name="viewport" content="width=1024" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>impress.js | 使用现代浏览器中css3的tranforms和trasitions特性进行展示的工具 | by Bartek Szopka @bartaz | 翻译ed by xishui @</title>
<meta name="description" content="impress.js is a presentation tool based on the power of CSS3 transforms and transitions in modern browsers and inspired by the idea behind" />
<meta name="author" content="Bartek Szopka" />
<link href=",semibold,italic,italicsemibold|PT+Sans:400,700,400italic,700italic|PT+Serif:400,700,400italic,700italic" rel="stylesheet" />
Impress.js doesn't depend on any external stylesheet. Script adds all styles it needs for
presentation to work.
This style below contains styles only for demo presentation. Browse it to see how impress.js
classes are used to style presentation steps, or how to apply fallback styles, but I don't want
you to use them directly in your presentation.
Be creative, build your own. We don't really want all impress.js presentations to look the same,
do we?
When creating your own presentation get rid of this file. Start from scratch, it's fun!
接下来的demo的格式仅仅是用于普通的演讲风格的,或者是作为备用格式,哥不希望你直接用在你的演讲里面啊。(twitter Bootstrap继续泪目)
<link href="css/impress-demo.css" rel="stylesheet" />
<link rel="shortcut icon" href="favicon.png" />
<link rel="apple-touch-icon" href="apple-touch-icon.png" />
Body element is used by impress.js to set some useful class names, that will allow you to detect
the support and state of the presentation in CSS or other scripts.
First very useful class name is `impress-not-supported`. This class means, that browser doesn't
support features required by impress.js, so you should apply some fallback styles in your CSS.
It's not necessary to add it manually on this element. If the script detects that browser is not
good enough it will add this class, but keeping it in HTML means that users without JavaScript
will also get fallback styles.
When impress.js script detects that browser supports all required features, this class name will
be removed.
The class name on body element also depends on currently active presentation step. More details about
it can be found later, when `hint` element is being described.
<body class="impress-not-supported">
For example this fallback message is only visible when there is `impress-not-supported` class on body.
举个栗子,这里的备用信息只会在当 impress-not-supported 在body元素里时才可见。
<div class="fallback-message">
<p>为了欣赏漂亮的演示画面,请使用先进、优雅、快速、美丽、免费的现代浏览器,比如 <b>Chrome</b>, <b>Safari</b> or <b>Firefox</b> 。</p>
Now that's the core element used by impress.js.
That's the wrapper for your presentation steps. In this element all the impress.js magic happens.
It doesn't have to be a `<div>`. Only `id` is important here as that's how the script find it.
You probably won't need it now, but there are some configuration options that can be set on this element.
To change the duration of the transition between slides use `data-transition-duration="2000"` giving it
a number of ms. It defaults to 1000 (1s).
You can also control the perspective with `data-perspective="500"` giving it a number of pixels.
It defaults to 1000. You can set it to 0 if you don't want any 3D effects.
If you are willing to change this value make sure you understand how CSS perspective works:
But as I said, you won't need it for now, so don't worry - there are some simple but interesing things
right around the corner of this tag ;)
如果要修改幻灯片之间的过度时间请用这样的 data-transition-duration="2000" 将其设置为2000毫秒(2秒)。默认的时间是1秒。
你也可以设置幻灯片的视角,比如 data-perspective="500" ,默认的是1000。如果你不喜欢3D效果的话你也可以设置这个值为0。
<div id="impress">
Here is where interesting thing start to happen.
Each step of the presentation should be an element inside the `#impress` with a class name
of `step`. These step elements are positioned, rotated and scaled by impress.js, and
the 'camera' shows them on each step of the presentation.
Positioning information is passed through data attributes.
In the example below we only specify x and y position of the step element with `data-x="-1000"`
and `data-y="-1500` attributes. This means that **the center** of the element (yes, the center)
will be positioned in point x = -1000px and y = -1500px of the presentation 'canvas'.
It will not be rotated or scaled.
演示文稿的没一步都应该放在 #impress 中,以及一个叫做 step 的类名。这些 step 元素被impress.js所确定位置,旋转和缩放,监视器会显示演示的每一步。(这一段我也不是太懂。)
在接下来的例子中我们仅仅用 data-x="-1000" 和 data-y="-1500 指定步元素中x和y的位置。这就意味着元素的中心,是的,就是中心,将会被挪到 x = -1000px 和 y = -1500px 的这个点。
<div id="bored" class="step slide" data-x="-1000" data-y="-1500">
<q>你是不是觉得传统的幻灯片都 <b>弱爆了</b> ?</q>
The `id` attribute of the step element is used to identify it in the URL, but it's optional.
If it is not defined, it will get a default value of `step-N` where N is a number of slide.
So in the example below it'll be `step-2`.
The hash part of the url when this step is active will be `#/step-2`.
You can also use `#step-2` in a link, to point directly to this particular step.
Please note, that while `#/step-2` (with slash) would also work in a link it's not recommended.
Using classic `id`-based links like `#step-2` makes these links usable also in fallback mode.
如果它没有被定义,它将会获得一个默认的值 step-N ,N是当前幻灯的页数。
因此在接下来的例子里它将会获得 step-2 。
如果这一部分被激活,url将会变成 #/step-2 。
因此你也可以在链接里使用 #/step-2 ,直接指向这一页。
但是啊,少年你还是少用这种不符合标准的形式吧,如果你使用经典的方法比如 #step-2 ,那么即使用户不支持也可以使用备用效果。
<div class="step slide" data-x="0" data-y="-1500">
<q>你有没有想过,在 <strong>现代浏览器</strong> 光辉下,我们可以不再受限于 <strong>老旧浏览器的残忍压迫</strong> ?</q>
<div class="step slide" data-x="1000" data-y="-1500">
<q>你难道不想使用 <strong>华丽的舞台效果</strong> 来 <strong>震惊你的观众</strong> 吗?</q>
This is an example of step element being scaled.
Again, we use a `data-` attribute, this time it's `data-scale="4"`, so it means that this
element will be 4 times larger than the others.
From presentation and transitions point of view it means, that it will have to be scaled
down (4 times) to make it back to it's correct size.
我们再次使用了 data- 的办法,这次用了 data-scale="4" ,它的意思是这个元素将会比其他的(这里指的是默认大小)大4倍。
<div id="title" class="step" data-x="0" data-y="0" data-scale="4">
<span class="try">那么,您应该尝试一下</span>
<span class="footnote"><sup>*</sup>美式的小幽默,无视</span>
This element introduces rotation.
Notation shouldn't be a surprise. We use `data-rotate="90"` attribute, meaning that this
element should be rotated by 90 degrees clockwise.
我们用 data-rotate="90" ,意思是该元素将会顺时针旋转90度。(当然少年你也可以旋转个几万度来烧机子啊。)
<div id="its" class="step" data-x="850" data-y="3000" data-rotate="90" data-scale="5">
<p>它是一个 <strong>演示工具</strong> <br/>
受<a href=""></a>启发 <br/>
基于现代浏览器中 <strong>强大的CSS3特效</strong> 开发而成</p>
<div id="big" class="step" data-x="3500" data-y="2100" data-rotate="180" data-scale="6">
<p>它可以具象化您 <big style="font-size:larger">伟大</big> </p>
And now it gets really exiting! We move into third dimension!
Along with `data-x` and `data-y`, you can define the position on third (Z) axis, with
`data-z`. In the example below we use `data-z="-3000"` meaning that element should be
positioned far away from us (by 3000px).
使用 data-x 与 data-y 两个元素,你可以用 data-z 来定义第三坐标轴 Z 的存在。在这个例子中我们将会使用 data-z="-3000"来使这个元素远离我们3000px。
<div id="tiny" class="step" data-x="2825" data-y="2325" data-z="-3000" data-rotate="300" data-scale="1">
<p>或者 <span style="font-size:smaller">细致</span> 的 <span class="thoughts">想法</span></p>
This step here doesn't introduce anything new when it comes to data attributes, but you
should notice in the demo that some words of this text are being animated.
It's a very basic CSS transition that is applied to the elements when this step element is
At the very beginning of the presentation all step elements are given the class of `future`.
It means that they haven't been visited yet.
When the presentation moves to given step `future` is changed to `present` class name.
That's how animation on this step works - text moves when the step has `present` class.
Finally when the step is left the `present` class is removed from the element and `past`
class is added.
So basically every step element has one of three classes: `future`, `present` and `past`.
Only one current step has the `present` class.
在最开始的时候,所有的元素都会被分类到 future 中,这意味着他们没有被访问过。
当幻灯片开始移动使 future 的类移动到 present。
这也是为什么刚才那一页能够工作的原因-当这一页变成成 present 的时候文字就会移动。
最终这一页又会从 present 变化为 past 。
所以所有的页面都会有 future present past 三种类,只有当前正在运行的页面才会有 present 这个类。
<div id="ing" class="step" data-x="3500" data-y="-850" data-rotate="270" data-scale="6">
<p>它在一个无线大的画布上,展示了 <b class="positioning">定位</b> , <b class="rotating">旋转</b> 和 <b class="scaling">缩放</b> 的特效</p>
<div id="imagination" class="step" data-x="6700" data-y="-300" data-scale="6">
<p><b class="imagination">心</b>有多大,<b>舞台</b>就有多大</p>
<div id="source" class="step" data-x="6300" data-y="2000" data-rotate="20" data-scale="4">
<q><a href="">查看源码吧</a>, 兄台!</q>
<div id="one-more-thing" class="step" data-x="6000" data-y="4000" data-scale="2">
And the last one shows full power and flexibility of impress.js.
You can not only position element in 3D, but also rotate it around any axis.
So this one here will get rotated by -40 degrees (40 degrees anticlockwise) around X axis and
10 degrees (clockwise) around Y axis.
You can of course rotate it around Z axis with `data-rotate-z` - it has exactly the same effect
as `data-rotate` (these two are basically aliases).
在这一页你可以感受到 impress.js 强大的力量和百变的灵活性。
这里这个例子会让他围绕 X 轴旋转-40度(逆时针40°)再围绕 Y 轴旋转10度。
你当然也可以使用 data-rotate-z 使元素围绕 Z 轴旋转,这当然和 data-rotate 效果是类似的。
<div id="its-in-3d" class="step" data-x="6200" data-y="4300" data-z="-100" data-rotate-x="-40" data-rotate-y="10" data-scale="2">
<p><span class="have">你</span> <span class="you">有没有</span> <span class="noticed">注意到</span> <span class="its">它</span> <span class="in">是</span> <b>3D<sup>*</sup></b>的?</p>
<span class="footnote">* prezi可没这能力</span>
So to make a summary of all the possible attributes used to position presentation steps, we have:
* `data-x`, `data-y`, `data-z` - they define the position of **the center** of step element on
the canvas in pixels; their default value is 0;
* `data-rotate-x`, `data-rotate-y`, 'data-rotate-z`, `data-rotate` - they define the rotation of
the element around given axis in degrees; their default value is 0; `data-rotate` and `data-rotate-z`
are exactly the same;
* `data-scale` - defines the scale of step element; default value is 1
These values are used by impress.js in CSS transformation functions, so for more information consult
CSS transfrom docs:
* data-x、data-y、data-z——他们定义以该点位置为中心的页面;它们的缺省值为0;
* data-rotate-x、data-rotate-y、data-rotate-z、data-rotate——他们定义为令元素围绕指定的坐标轴旋转指定度数;它们的缺省值是0,“data-rotate”和“data-rotate-z”是相似的;
CSS transfrom文档:
<div id="overview" class="step" data-x="3000" data-y="1500" data-scale="10">
Hint is not related to impress.js in any way.
But it can show you how to use impress.js features in creative way.
When the presentation step is shown (selected) its element gets the class of "active" and the body element
gets the class based on active step id `impress-on-ID` (where ID is the step's id)... It may not be
so clear because of all these "ids" in previous sentence, so for example when the first step (the one with
the id of `bored`) is active, body element gets a class of `impress-on-bored`.
This class is used by this hint below. Check CSS file to see how it's shown with delayed CSS animation when
the first step of presentation is visible for a couple of seconds.
And when it comes to this piece of JavaScript below ... kids, don't do this at home ;)
It's just a quick and dirty workaround to get different hint text for touch devices.
In a real world it should be at least placed in separate JS file ... and the touch content should be
probably just hidden somewhere in HTML - not hard-coded in the script.
Just sayin' ;)
还有那个 just sayin 闹哪样了啊!!我看了半天发现这是开玩笑的……
<div class="hint">
if ("ontouchstart" in document.documentElement) {
document.querySelector(".hint").innerHTML = "<p>向左或向右拖动屏幕来移动</p>";
Last, but not least.
To make all described above really work, you need to include impress.js in the page.
I strongly encourage to minify it first.
In here I just include full source of the script to make it more readable.
You also need to call a `impress().init()` function to initialize impress.js presentation.
And you should do it in the end of your document. Not only because it's a good practice, but also
because it should be done when the whole document is ready.
Of course you can wrap it in any kind of "DOM ready" event, but I was too lazy to do so ;)
当然你可以使用“DOM ready”事件,但是我比较懒;)
<script src="js/impress.js"></script>
The `impress()` function also gives you access to the API that controls the presentation.
Just store the result of the call:
var api = impress();
and you will get three functions you can call:
`api.init()` - initializes the presentation,
`` - moves to next step of the presentation,
`api.prev()` - moves to previous step of the presentation,
`api.goto( idx | id | element, [duration] )` - moves the presentation to the step given by its index number
id or the DOM element; second parameter can be used to define duration of the transition in ms,
but it's optional - if not provided default transition duration for the presentation will be used.
You can also simply call `impress()` again to get the API, so `impress().next()` is also allowed.
Don't worry, it wont initialize the presentation again.
For some example uses of this API check the last part of the source of impress.js where the API
is used in event handlers.
`impress()` 函数给了你一个控制演示API的方法。
var api = impress();
`api.init()` - 初始化演示;
`` - 播放下一个幻灯片;
`api.prev()` - 回到上一个幻灯片;
`api.goto( idx | id | element, [duration] )` - 通过知道那个id或者DOM播放指定的幻灯片
Now you know more or less everything you need to build your first impress.js presentation, but before
you start...
Oh, you've already cloned the code from GitHub?
You have it open in text editor?
Stop right there!
That's not how you create awesome presentations. This is only a code. Implementation of the idea that
first needs to grow in your mind.
So if you want to build great presentation take a pencil and piece of paper. And turn off the computer.
Sketch, draw and write. Brainstorm your ideas on a paper. Try to build a mind-map of what you'd like
to present. It will get you closer and closer to the layout you'll build later with impress.js.
Get back to the code only when you have your presentation ready on a paper. It doesn't make sense to do
it earlier, because you'll only waste your time fighting with positioning of useless points.
If you think I'm crazy, please put your hands on a book called "Presentation Zen". It's all about
creating awesome and engaging presentations.
Think about it. 'Cause impress.js may not help you, if you have nothing interesting to say.
如果你觉得我在胡扯,去看看一本叫做"Presentation Zen"(中译《演说之禅》,貌似还没有中文版)
Are you still reading this?
For real?
I'm impressed! Feel free to let me know that you got that far (I'm @bartaz on Twitter), 'cause I'd like
to congratulate you personally :)
But you don't have to do it now. Take my advice and take some time off. Make yourself a cup of coffee, tea,
or anything you like to drink. And raise a glass for me ;)