26
Thu, Dec
0 New Articles

CSS Animation for the IBM i

Development Tools / Utilities
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

The current incarnation of the web-styling language CSS provides some nice and simple-to-implement animation capabilities.

 

The current incarnation of the web-styling language CSS provides animation capabilities that hitherto were only available in JavaScript or the third-party software known as Flash. The Apple brand mobile devices will not run Flash, and not all Androids run it either. Enter CSS3 animation; Flash is dead!

 

Why Animate?

In today's world, more people access the Internet via their mobile devices than from desktop PCs. The paucity of screen real estate on a mobile device demands the economic use of the available space. Through the use of animation, additional content such as a navigation menu can slide in and overlay the current page content.

 

Animation can be used to bring the user's attention to particular elements on a page. And animation, when used wisely, gives the site a slick and professional appearance.

 

As more and more companies that use the IBM i modernize their applications by rendering them to the browser, animation will come into our world.

 

 

This article will guide you through creating animations that will execute on our preferred server.

 

The Basics of CSS Animation

There are directives in CSS3 known as Transforms, which, as the name suggests, transform an element from its original state to another form. These transforms are Skew, Rotate, Scale, and Translate. The name of the latter (Translate) is a little ambiguous and is really just a "move."

 

In addition to Transforms, there are timing directives known as Keyframes (coded as @keyframe). Keyframes define the timing of the animation and can additionally include other element style changes for example, the background colorat particular points in the animation.

 

The original, named element and the Keyframe combine to effect the animation.

 

An Animation Example

Our example is a square defined using the HTML tag <Fieldset>, viz:

 

           <fieldset>

           <pre><br><br>

          Hello Animation!

           </pre>

</fieldset

 

This is the CSS styling:

 

fieldset {

   background-color:#000080;color: #ffffff;

   text-align:center;

   width:200px;height:200px;

   font-size:1.5em;

   position: relative;top:-25px;

   margin:25px;

}

 

The code gives the following rendering:

 

011316SeeneyFig1

Figure 1: Note the blue background and the square corners.

 

An Example Using the Skew Transform

The first example will skew the element. To do this, we add the element definition to the animation directives:

 

fieldset {

   background-color:#000080;color: #ffffff;

   text-align:center;

   width:200px;height:200px;

   font-size:1.5em;

   position: relative;top:-25px;

   margin:25px;

      animation-name: animation;

      animation-duration: 8s;

      animation-delay: 2s;

}

 

This code names the animation as "animation1." It will run for 8 seconds and has a delayed start of 2 seconds.

 

The keyframe definition would look as follows:

 

@keyframes animation {

                                   from { }

                                   to   {   transform: skew(15deg,20deg); }

}

 

The key frame has a simple "from" and "to" specification. No styling elements will be changed at start, but the element will be skewed over a period of 8 seconds, where the X-axis skew is 15 degrees and the Y-axis is 20 degrees. (There are two other related transformsSkewX and SkewYwhere only one parameter is specified.)

 

011316SeeneyFig2

Figure 2: Click to run the animation.

 

The example above is a simple case, and the keywords "from" and "to" have been used. An animation usually goes through several changes throughout its duration, so typically percentages are used. A three-step @keyframe might look as follows:

 

@keyframes animation {

         0%   {       }

       50%   {   transform: skew(15deg,20deg); }

       100%   {   transform: skew(30deg,40deg); }

}

 

 

Vendor Prefixes

A small drawback in CSS3 animations is that the renderings are browser-specific. This forces us to declare the browser we want the animation to run on within the CSS element specification and the @keyframe specification. Otherwise, the animation won't work.

 

For each CSS3 style specification that includes a transform and for each @keyframe specification, we need to include a vendor prefix. So our code really needs to look as follows to run on all of the popular browsers:

 

fieldset {

   background-color:#000080;color: #ffffff;

   text-align:center;

   width:200px;height:200px;

   font-size:1.5em;

   position: relative;top:-25px;

   margin:25px;

      -webkit-animation-name: animation;

      -webkit-animation-duration: 8s;

      -webkit-animation-delay: 2s;

      -ms-animation-name: animation;

      -ms-animation-duration: 8s;

      -ms-animation-delay: 2s;

      -moz-animation-name: animation;

      -moz-animation-duration: 8s;

      -moz-animation-delay: 2s;

      -o-animation-name: animation;

      -o-animation-duration: 8s;

      -o-animation-delay: 2s;

}

 

Where –webkit- represents Chrome and Safari

             -ms-       Microsoft's Internet Explorer

             -moz-      FireFox

-o-   Opera.     

 

Similarly, we need to include the vendor prefixes on the @keyframe tags:

 

            @-webkit-keyframes animation {

                 from {}

                 to { transform: scale(0.5); }

            }

            @-ms-keyframes animation {

                 from {}

                 to { transform: scale(0.5); }

            }

            @-moz-keyframes animation {

                 from {}

                 to { transform: scale(0.5); }

            }

            @-o-keyframes animation {

                 from {}

                 to { transform: scale(0.5); }

            }

 

For sure, this is an annoyance that we have to deal with, and it makes the scripts containing animations unnecessarily verbose in my opinion. Animation directives without a prefix work only for IE, but not all directives work on early versions of IE.

 

For the benefit of this article, the examples below omit the vendor prefixes but they will be included in the source code of the demonstration scripts.

 

An Example Using the Rotate Transform

Leaving the basic CSS element unchanged, the @keyframe would look as follows:

 

      @keyframes animation {

           from {}

           to {   transform: rotate(45deg); }

}

 

 

011316SeeneyFig3

Figure 3: Click to run the animation.

 

An Example Using the Scale Transform

Leaving the basic CSS element unchanged, the @keyframe would look as follows:

 

      @keyframes animation {

           from {}

           to {  transform: scale(0.5);}

       }

 

The animation shrinks the element to 50% of its original size.

 

011316SeeneyFig4

Figure 4: Click to run the animation.

 

An Example Using the Translate Transform

Leaving the basic CSS element unchanged, the @keyframe would look as follows:

 

      @keyframes animation {

           from {}

           to {   transform: translate(600px,-50px); }

       }

 

The animation moves the element to 600 pixels to the right and 50 pixels up from its initial position.

 

011316SeeneyFig5

Figure 5: Click to run the animation.

 

Multiple Animations

Not surprisingly, we can combine transforms to create more-complex animations. In this example, 100% is used instead of the keyword "To".

 

Example:

100% {   transform:                     skew(15deg,20deg)

                        rotate(45deg)

                        scale(0.5)

                        translate(300px,-50px)

                 }

                     

Style Changes During Animations

In addition to specifying animation directives, the @keyframe can also specify style changes to the element. In the following @keyframe example, the animation has been changed to have three states, and halfway through (at 50%), the element's corners will be rounded and the background color will change. In the final step of the animation (at 100%), the corners are further rounded and the background color changes again.

 

@keyframes animation {

   0% {

      }

50% {

      border-radius:25% 25% 25% 25%;

      background-color:008800;

      transform: skew(7.5deg,10deg)

                        rotate(22deg)

                        scale(0.75)

                        translate(150px,-25px)

      }

   100% {

      background-color:880000;

      border-radius:50% 50% 50% 50%;

      transform: skew(15deg,20deg)

                        rotate(45deg)

                        scale(0.5)

                        translate(300px,-50px)

      }

}

 

Additional Transforms

There are some additional Transforms that can be used to great effect.

 

This directive causes the animation to play continuously:

animation-iteration-count: infinite;

 

This directive causes the animation to play from start to finish and back again:

animation-direction: alternate;

           

This directive causes the animation to start slowly, accelerate to normal speed, and then slow down again as the animation approaches the end:

animation-timing-function: ease-in-out;

 

Other values for this directive are ease-in, ease-out, and cubic-bezier. The latter is a means whereby you can define your own timing function.

 

By adding these transforms to our original element, we get this:

 

fieldset {

   background-color:#000080;color: #ffffff;

   text-align:center;

   width:200px;height:200px;

   font-size:1.5em;

   position: relative;top:-25px;

   margin:25px;

      animation-name: animation;

      animation-duration: 8s;

      animation-delay: 2s;

      animation-direction: alternate;      

animation-iteration-count: infinite;

animation-timing-function: ease-in-out;

}

 

After incorporating these additional directives, we get a more-sophisticated animation:

 

 

011316SeeneyFig6

Figure 6: Click to run the animation.

 

Animate!

As you can see, including animation in your web pages isn't difficult. Although the examples contained herein are all flat HTML files, CGI programs written in RPG can easily produce the same result. The animations addressed in this article are all two-dimensional, but CSS3 has the ability to render three-dimensional animation, which can be used, say, to rotate images of products 360 degrees. But we'll save that discussion for another day.

 

Finally, don't forget the vendor prefixes in your code to ensure that your animation works with all the browsers.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: