DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Dynamically Skipping Animations in Edge Animate

Raymond Camden user avatar by
Raymond Camden
·
Dec. 20, 12 · Interview
Like (0)
Save
Tweet
Share
3.41K Views

Join the DZone community and get the full member experience.

Join For Free

as much as i like animation, sometimes less is more. i know we've all seen cool animations that were, well, cool, but after you've seen it a few times you wish you could simply bypass it. here's a simple example of how you can modify an edge animate project to remember that a user has seen the animation and skip to the end.

i began by creating an incredibly simple animation. i added a text box that flew in and increased in size. the entire animation stretched out over 3 seconds. take a gander at the demo here: http://www.raymondcamden.com/demos/2012/dec/4/welcomeproject2/

amazing, right? i know, i'm wasting my time as a developer when i should be in the interactive design business. ok, that aside, the first thing i did was disable autoplay and created a "creationcomplete" event handler. i discussed this earlier in another blog post: data-driven edge animate projects .

at this point i've got an animation that won't do anything, so i need to build that logic in. i decided to use window.sessionstorage as a simple way to note that you've already seen the animation. there's many other options i could have used, like cookies, but i figured this was the quickest, simplest way of doing it. let's take a look at the code.

symbol.bindsymbolaction(compid, symbolname, "creationcomplete", function(sym, e) {
    if(!window.sessionstorage || (window.sessionstorage && !window.sessionstorage.getitem("seenanimation"))) {
        sym.play(0);
        if(window.sessionstorage) window.sessionstorage.setitem("seenanimation",1);
    } else {
        sym.play(sym.getduration()-1);
    }
});

in a nutshell, the code first checks to see if your browser even supports sessionstorage, and if it does, it looks for the existence of a "seenanimation" variable. again, we have options here. instead of a "once a session" flag i could use a counter. or a date variable that only shows the animation every 5 minutes. you get the idea.

the else portion is interesting. my animation is 3 seconds long. so at first i tried play(3000) but it didn't work. i then added a label called "end" and tried play("end"). turns out, the play() api is 0-based. (documented here .) so i simply used the getduration() api and substracted one from it.

obviously you wouldn't have to go to the end either. maybe you just want to skip part of the animation or go to some other label. you can play with this demo below.

Label Design dev POST (HTTP) Build (game engine) Session (web analytics) Event Blog

Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Brief Overview of the Spring Cloud Framework
  • ChatGPT Prompts for Agile Practitioners
  • Top 5 Node.js REST API Frameworks
  • Load Balancing Pattern

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: