{"id":1410,"date":"2013-11-19T11:48:51","date_gmt":"2013-11-19T10:48:51","guid":{"rendered":"http:\/\/meier-online.com\/?p=1410"},"modified":"2015-02-16T18:03:54","modified_gmt":"2015-02-16T17:03:54","slug":"rolling-billboard-css","status":"publish","type":"post","link":"https:\/\/meier-online.com\/en\/2013\/11\/rolling-billboard-css\/","title":{"rendered":"Rotating Billboard with CSS-Animations"},"content":{"rendered":"<p><a href=\"http:\/\/meier-online.com\/develop\/jquery\/billboard-cssani.html\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-1336\" src=\"http:\/\/meier-online.com\/blog\/uploads\/billboard-with-arrow-150.png\" alt=\"Billboard with changing pictures\" width=\"150\" height=\"150\" \/><\/a>In 1998, I have presented &#8220;Meier&#8217;s billboard&#8221;. It is a virtual display panel with changing images. I have developed it as Java-applet. In 2009, I have rewritten the\u00a0<a title=\"Article about rotating billboard with mit jQuery\" href=\"http:\/\/meier-online.com\/en\/2009\/08\/rolling-billboard-jquery\/\">billboard with JavaScript and jQuery<\/a>.<\/p>\n<p>Today we can define simple animations in CSS3 style definitions. Thus, we can build a rotating advertising Billboard without JavaScript.<\/p>\n<h3>Basic Structure:<\/h3>\n<p>We set up the basic framework like in the solution with JavaScript:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-594 alignnone\" src=\"http:\/\/meier-online.com\/blog\/uploads\/billboardschema.png\" alt=\"Funktionsweise: Eine Liste von Bildern wird unter einem Fenster hindurchgeschoben.\" width=\"360\" height=\"280\" srcset=\"https:\/\/meier-online.com\/blog\/uploads\/billboardschema.png 360w, https:\/\/meier-online.com\/blog\/uploads\/billboardschema-300x233.png 300w\" sizes=\"(max-width: 360px) 100vw, 360px\" \/><\/p>\n<p>There is a frame and a list of images. The meaning of frame here is that of a picture-frame, not that of a HTML-frame.<\/p>\n<p>We manipulate the &#8220;top&#8221; coordinate of the list to create the motion. The clipping property is responsible to let us see only the inside of the frame.<\/p>\n<h3>Animation<\/h3>\n<p>The definition of a css-animation consists of two parts.<\/p>\n<p>The first part is the definition of &#8220;key frames&#8221;, so the key scenes. In the simplest case, we need only two key frames: an opening scene and a final scene. If we want to move an image 200 points upwards, we use a definition like this:<\/p>\n<pre>@keyframes slideup {  \r\n  from {    top: 0px;  }  \r\n  to {    top: -200px;  }\r\n}<\/pre>\n<p>On the next we must determine an element on which the newly-defined animation is applied. In addition we can determine parameters for this animation here: when it starts, and how often it is repeated. The &#8216;animation-name&#8217; field name must match the @keyframes-element.<\/p>\n<pre>#billboard ul li{   \r\n  animation-delay: 1s;   \r\n  animation-duration: 3s;   \r\n  animation-iteration-count: infinite;   \r\n  animation-name: slideup;  \r\n... \r\n}<\/pre>\n<p>This works good so far:<\/p>\n<p>[button link=&#8221;\/develop\/jquery\/billboard-cssani-step1.html&#8221; color=&#8221;green&#8221; target=&#8221;blank&#8221;]Demo[\/button]<\/p>\n<h3>Multiple images<\/h3>\n<p>We want to show more than two images in our billboard. But CSS is no imperative programming language, so we can not put together the animations in a controlled way like with JavaScript.<\/p>\n<p>Instead can we do the opposite, and divide the large animation with small intermediate steps. The points of time of the intermediate steps are specified as a percentage of the total animation:<\/p>\n<pre>@keyframes slideup {   \r\n  from { top: 0px; }   \r\n  16% { top: -200px; }  \r\n  33% { top: -200px; }\r\n  50% { top: -400px; }   \r\n  67% { top: -400px; }  \r\n  84% { top: -600px; }   \r\n  to { top: -600px; } \r\n}<\/pre>\n<p>The billboard is almost ready for use: we need to increase the animation duration compared with our original solution, as we now specify the duration of a passage of all images.<\/p>\n<p>To achieve a clean transition between last and first image, we reuse the trick to repeat the first image after the last image.<\/p>\n<p>[button link=&#8221;\/develop\/jquery\/billboard-cssani.html&#8221; color=&#8221;green&#8221; target=&#8221;blank&#8221;]Demo[\/button]<\/p>\n<p>You find the source code in my repository on Github.<\/p>","protected":false},"excerpt":{"rendered":"<p class=\"qtranxs-available-languages-message qtranxs-available-languages-message-en\">Sorry, this entry is only available in <a href=\"https:\/\/meier-online.com\/de\/wp-json\/wp\/v2\/posts\/1410\" class=\"qtranxs-available-language-link qtranxs-available-language-link-de\" title=\"Deutsch\">Deutsch<\/a>.<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[104],"tags":[192,190,220],"class_list":["post-1410","post","type-post","status-publish","format-standard","hentry","category-develop","tag-animation","tag-css","tag-ux","entry"],"_links":{"self":[{"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/posts\/1410"}],"collection":[{"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/comments?post=1410"}],"version-history":[{"count":23,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/posts\/1410\/revisions"}],"predecessor-version":[{"id":1984,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/posts\/1410\/revisions\/1984"}],"wp:attachment":[{"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/media?parent=1410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/categories?post=1410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meier-online.com\/en\/wp-json\/wp\/v2\/tags?post=1410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}