Hire a web Developer and Designer to upgrade and boost your online presence with cutting edge Technologies

Saturday, August 17, 2013

Introducing Jelly Navigation Menu: When Canvas Meets PaperJS

It’s our great pleasure to support active members of the Web design and development community. Today, we’re proud to present the Jelly Navigation Menu that shows the power of PaperJS and TweenJS when used together. This article is yet another golden nugget of our series of various tools, libraries and techniques.
There is no doubt that the Web helps designers and developers find the best inspiration and resources for their projects. Even though there are a bunch of different tutorials and tips available online, I feel that HTML5 canvas techniques are missing the most. Good news: I had the chance to fulfill this wide gap. In this article, I would like to share my experience and story of how I brought the “Jelly Navigation Menu” to life. Credits go to Capptivate.co and Ashleigh Brennan’s icons — they were my inspiration for this project.

Before We Start

The source code for this project was originally written in CoffeeScript — I believe it’s a better way to express and share JavaScript code that way. I will refer to CoffeScript’s source in code sections within this post and you’ll also notice links to CodePens that have been rewritten in JavaScript and represent local parts of code as well. I recommend downloading the source code on GitHub so you can easily follow me while I explain the necessary code in detail.
I used PaperJS for the canvas graphics and TweenJS for the animations. Both of them tend to freak out some folks, but don’t worry, they are really intuitive and easy to understand. If you’d like to learn how to set up PaperJS and TweenJS environments, you can fork this cool bootstrap pen for online fun or this git repo if you want to experiment locally.

A preview of the Jelly Navigation Menu.

First Step: Changing The Section Shape

Our first aim is to change the menu section shape by manipulating the curves. Every object is made up of anchor points. These points are connected with each other by curves. So each point has “In” and “Out” handles to define the location and direction of specific curves. Folks who work with vector editors should feel comfortable with this step.

In Paper.js, paths are represented by a sequence of segments that are connected by curves. A segment consists of a point and two handles, defining the location and direction of the curves. See the handles in action.
All we need to do is to change the handleOut position of the top-left and bottom-right points. To achieve this, I wrote simple so-called “toppie” and “bottie” functions:
toppie:(amount)->
  @base.segments[1].handleOut.y = amount
  @base.segments[1].handleOut.x = (@wh/2)

bottie:(amount)->
  @base.segments[3].handleOut.y = amount
  @base.segments[3].handleOut.x = - @wh/2

# @wh/2 is section center.
# @base variable holds section's rectangle path.
It’s important to set the handle’s X position to exactly the middle of the section, so that the curve will turn out to be symmetrical.

Second Step: Calculating The Scrolling Speed

So the next thing that needs to be done is to calculate the scrolling speed and direction, and then pass this data to the bottie and toppie functions. We can listen to the container’s scrolling event and determine the current scrolling position (in my case the “container” is a #wrapper element whereas it is a window object in the pen examples).
# get current scroll value
window.PaperSections.next = window.PaperSections.$container.scrollTop()

# and calculate the difference with previous scroll position
window.PaperSections.scrollSpeed = (window.PaperSections.next - window.PaperSections.prev)

# to make it all work, all we have left to do is to save current scroll position to prev variable
window.PaperSections.prev = window.PaperSections.next
This is repeated for every scrolling event. In this code snippet, window.PaperSections is just a global variable. I also made a few minor additions in my implementation:
  • A silly coefficient to increase scroll speed by multiplying it by 1.2 (just played around with it),
  • I sliced the scroll speed result by its maximum so that it is not larger than sectionHeight/2,
  • I also added a direction coefficient (it could be 1 or -1, you can change it in dat.gui on the top right of the page). This way you can control the reaction direction of sections.
Here is the final code:
if window.PaperSections.i % 4 is 0
  direction = if window.PaperSections.invertScroll then -1 else 1
  window.PaperSections.next = window.PaperSections.$container.scrollTop()
  window.PaperSections.scrollSpeed = direction*window.PaperSections.slice 1.2*(window.PaperSections.next - window.PaperSections.prev), window.PaperSections.data.sectionheight/2
  window.PaperSections.prev = window.PaperSections.next
  window.PaperSections.i++
In this example, if window.PaperSections.i % 4 is 0 helps us react on every fourth scroll event — similar to a filter. That function lives in window.PaperSections.scrollControl.
That’s it! We’re almost done! It couldn’t be any easier, right? Try out the scrolling here.

Step Three: Make It Jelly!

In this final step, we need to animate the toppie and bottie functions to 0 with TweenJS’ elastic easing everytime the scrolling stops.

3.1 Determine When Scrolling Stops

To do this, let’s add the setTimeout function to our window.PaperSections.scrollControl function (or scroll) with 50ms delay. Each time when the scrolling event fires up, the Timeout is cleared except for the last one, i.e. once scrolling stops, the code in our timeout will execute.
clearTimeout window.PaperSections.timeOut
window.PaperSections.timeOut = setTimeout ->
  window.PaperSections.$container.trigger 'stopScroll'
  window.PaperSections.i = 0
  window.PaperSections.prev = window.PaperSections.$container.scrollTop()
    , 50
The main focus here is the window.PaperSections.$container.trigger stopScroll event. We can subscribe to it and launch the animation appropriately. The other two lines of code are simply being used to reset helper variables for later scrollSpeed calculations.

3.2 Animate Point’s handleOut To “0”

Next, we’ll write the translatePointY function to bring our jelly animation to life. This function will take the object as a parameter with the following key-value sets:
{
  // point to move (our handleOut point)
  point: @base.segments[1].handleOut,

  // destination point
  to: 0,

  // duration of animation
  duration: duration
}
The function body is made up of the following:
translatePointY:(o)->
  # create new tween(from point position) to (options.to position, with duration)
  mTW = new TWEEN.Tween(new Point(o.point)).to(new Point(o.to), o.duration)

  # set easing to Elastic Out
  mTW.easing TWEEN.Easing.Elastic.Out
        
  # on each update set point's Y to current animation point
  mTW.onUpdate ->
    o.point.y = @y

  # finally start the tween
  mTW.start()
The TWEEN.update() function also has to be added to every frame of the PaperJS animation loop:
onFrame = ->
  TWEEN.update()
Also, we need to stop all animations on scrolling. I added the following line to the scroll listener function:
TWEEN.removeAll()
Finally, we need to subscribe to the stopScroll event and launch the animations by calling our translatePointY function:
window.PaperSections.$container.on 'stopScroll', =>
  # calculate animation duration
  duration = window.PaperSections.slice(Math.abs(window.PaperSections.scrollSpeed*25), 1400) or 3000

  # launch animation for top left point
  @translatePointY(
    point:      @base.segments[1].handleOut
    to:           0
    duration: duration
  ).then =>
    # clear scroll speed variable after animation has finished
    # without it section will jump a little when new scroll event fires
    window.PaperSections.scrollSpeed = 0
         
  # launch animation for bottom right point
  @translatePointY
    point:      @base.segments[3].handleOut
    to:           0
    duration: duration
Et voilĂ !
Note: In my source code of the translatePointY function, I added a deferred object for chaining, optional easing and onUpdate function. It is omitted here for the sake of simplicity.

In Conclusion

Last but not least, a class for the sections has to be added. Of course, you can make as many instances of it as you like; you just need to define initial Y offset and colors. Also, you will need to make sure that the section in your layout has the same height as the section in canvas. Then we can just apply translated3d to both on the scroll event and animations. This will cause HTML sections to move properly, just like the canvas sections, and hence produce a realistic animation.
HTML Sections
The reason why we need to use translate3d instead of translateY is to make sure that Webkit rendering engines use hardware acceleration while rendering them, so we do not drop out of the 60fps animation budget. But keep your eyes wide open if your sections contain any text. 3D transforms will drop anti-aliasing from subpixel to grayscale, so it may look a bit blurry!

Useful InDesign Scripts And Plugins To Speed Up Your Work

Few applications feel as complete as Adobe’s InDesign. First released in 1999 as a direct attack against the then-industry standard, Quark, the page-layout application has been made faster and more feature-rich with each iteration. But even the best applications lack some features. Luckily, Adobe realized this some years ago and opened the doors to allow designers to expand this beloved set of tools through plugins.
Many designers don’t realize how powerful InDesign can be, especially when expanded through plugins and scripts. So, we’ve put together a small collection to show a bit of what InDesign can do. More than anything, these will help you work through your documents and publications much faster, automating the repetitive parts, and freeing you to focus on the fun stuff.

Working With Text

As designers, we spend most of our time dealing with text, ensuring that it’s inviting, easy to read and easy to navigate. We often give the finest attention to text, working with spacing to give the text balance and rhythm, sometimes letter by letter. What follows is a collection of plugins to help you tend to these details.

Line Numbering

Line Numbering
This line-numbering plugin does exactly what it says on the box: it gives every line on a page a number. While InDesign is very capable of working with numbered lists, this plugin comes in handy when you don’t want the main text to display the numbers as you’re typesetting it — for example, because the text is lengthy and you’re still editing it. With this plugin, an extra text frame is added just for the numbers; so, once you delete it, the main copy won’t reflow. This makes editing much easier. “Please change the 34th line of copy” becomes a lot easier than “Please change the copy about three quarters of the way down the page.”

Fitting Text

Text Fitting in InDesign
Sometimes you’ll have set up a grid and want a bit of text — say, a heading or pull quote — to fit the available space to get a sense of how big the text should be relative to the page. You would normally do this by holding down the “enlarge text” shortcut or by punching in random sizes until you get one that fits. With this tool, it’s done for you at the click of a button.

All Caps to Small Caps

All Caps to Small Caps Script
Small caps aren’t simply full capitals made smaller. They’re specially crafted to sit beautifully on a line of text. As Robert Bringhurst says in his brilliant Elements of Typographic Style, “They differ from large caps in stroke weight, letterfit, and internal proportions as well as in height. Any good set of small caps is designed as such from the ground up.” In other words, they add polish to typesetting and prevent awkward strings of capital letters. This script runs through your text and replaces string of full caps with small caps. The best part? Character styling is automatically applied to them (a little extra tracking on small caps is a beautiful thing), so you can tinker as needed.

Proper Fractions

Proper Fraction
Just like the small-caps script above, this one will polish your type by rendering proper fractions, rather than leaving fractions in the clumsy format of two full-sized numerals divided by a slash.

Convert Footnotes to Sidenotes

Convert Footnotes to Sidenotes
Adding footnote is a nice way to clarify information. Even nicer is hanging notes in the margins. With this plugin, footnotes will be converted to sidenotes and put into their own anchored frames; so, as the text reflows and moves about, the sidenotes will move with the text.

Convert Footnotes to Endnotes

Convert footnotes to endnotes
From the same developer as the footnotes plugin above, this one will move your footnotes to the end of the article to which they belong. This is excellent if you’re working on a magazine or journal and the design calls for notes at the end of the article or essay.

Convert Multicolumn Text Frames to Individual Frames

Convert Multicolumn Text Frames to Individual Frames
While confining multi-column text to a single frame is usually best, sometimes breaking each frame into its own box makes the text easier to handle, especially when working with complex grids and formats (in newspapers, for example).

Merge Text Frames

Merge TextFrames Extension for Adobe InDesign
Other times, you’ll want to do the opposite and convert multiple frames to a single one to keep things neat.

Easy Diacritics

Easy Diacritics Characters
This script lets you combines any letter with any accent or diacritic using simple mnemonics — no arcane codes to remember, and no need to open the glyphs panel. If the combination exists as an actual glyph in the typeface, the script will insert that; if not, then it will automatically insert both glyphs and then intelligently kern them to look like a single character. InDesign Secrets explains how this works.

Working With Graphics And PDFs

Second only to text, links are what we spend most of our time on, sometimes creating them right in InDesign, and other times bringing them in as PDFs and TIFFs. The plugins and scripts below will supplement the importing options for both images of PDFs, as well as create graphics in InDesign itself.

Choose Object Style While Placing Pictures

Choose Object Style While Placing Pictures
Placing an image and applying a style is a two-step process that gets boring very quickly (especially if you’re producing a 200-page book for a gallery exhibition). With this script, it’s all automated. Just select an object style and start placing images. The style will automatically be applied, so that you can keep working quickly. (Note that this script was written for CS5.)

Easily Modify PDF Importing Options

Modify the PDF Import Options Very Easily
InDesign has come a long way in how it places PDFs. But once a PDF is placed, the options you’ve selected are locked. This script enables you to configure those options (such as which page of the PDF to show), even after the PDF has been placed.

Import Both PDF and INDD Files

MultiPageImporter for Importing both PDF and INDD Files
Automatically place the pages from a PDF or INDD file onto multiple pages in a document. Quick tip: Both types of files are treated like graphics; so, if you wish to view changes, go back and refresh the original files in the “Links” palette.

Place All Pages of a PDF in InDesign

Placing All the Pages of a PDF Inside InDesign
This PDF-placing script enables you to choose a page range from the PDF you’re placing, as well as the crop type. You can also specify which page in the InDesign document to start placing on (adding new pages as needed), where to place it on the page (with an optional offset), and whether to scale the PDF to the page’s size. If a document isn’t open, it will create one at the size of the PDF and then place the pages.

Column and Bar Graph Tools

Column and Bar Graph Tools
The bread and butter for a lot of designers are things like annual reports, which are often filled with charts and graphs. This script helps you quickly and easily create clean bar graphs based on given values.

Pie Charts Wizard

Pie Charts Wizard
Create pie charts with various options (color tint, size, radio and angle, labels, color mode, etc.). Coolest of all, as you adjust the size of the oval, each segment is automatically recalculated. Also consider testing the beta of Claquos 2.

Automation: Making A Lot Out Of A Little

If you perform the exact same task more than a few times, chances are the process can be automated somehow. Setting up the same type of job over and over (say, when designing calendars) can feel mundane. What follows are plugins and scripts that cut down on some of the repetition in your day.

Adobe InDesign Calendar Wizard

Adobe InDesign Calendar Wizard
Around the same time every year, every other client of ours seems to want a calendar of some sort. This feature-rich script creates a number of different calendars, from simple one-pagers to 12-month multi-page calendars with text, complete with holidays and moon phases.

Font Catalogue

Font Catalogue
Create a simple catalogue of all of the fonts on your system, including all weights and using your own sample text.
  • Developer: KID

Wordalizer

Indiplugins :: Wordalizer
Wordalizer is a word cloud generator for InDesign, available as a free trial or a pro version. It supports six languages, has a full word list editor, remembers your settings, lets you control word length, and more.

Scribbler Makes Text Look Shifty

Scribbler - A Shifty Look to Your Text
Wanna give your text some bounce? Set maximum top and bottom gap values, and Scribbler will randomly shift the characters. This is great if you’re working on something with a lot of illustrations, such as a children’s book or an editorial.

FontReporter

FontReporter
FontReporter collects information on the fonts used in your files, checks to see whether some fonts are missing, and tells you whether anything has gone wrong. You can choose to run it on just the current document or on a folder of documents.

MultiDo

MultiDo
The MultiDo plugin enables you to perform multiple undo or redo operations in one step. It automatically tracks the 100 most recent operations. This is incredibly handy when you’re quickly mocking up a design and are fine-tuning the text or images. If you want to jump far back quickly, you can do so, without having to watch as each bit of kerning and tracking you performed in the last hour is undone.

EasyHistory

EasyHistory
The “History” palette in Photoshop is incredibly handy and is one feature that is missing in InDesign. Luckily, while we wait around for Adobe to rectify this, EasyHistory does the job well, showing all available undo and redo steps in one convenient palette. It’s available as a limited demo or as a commercial version.

Multi-Find and Multi-Change

Multi-Find/Change
We often have to clean up the text that clients give us, whether because content is spaced out by multiple tabs, or every sentence is double spaced, or dashes and other typographic marks are not where they should be. This plugin will be incredibly useful for those who work with the same clients repeatedly and see the same issues come up. Multi-Find/Change enables you to batch run saved find-change queries. It’s available as a limited trial or, if you find it handy, a commercial version.

Professionalism With A Click

Who doesn’t like to be seen as a professional? From tracking time spent on work to setting up a job for printing, plugins are available to help you manage your relationship with clients.

Compare Two Documents

Compare two documents
Have you ever had a document crash and then weren’t sure what changes were made between the recovered version and your latest backup? Or perhaps you have multiple designers working on the same document? Or perhaps, during a particularly tense day, you weren’t careful about naming, versioning and saving your files and, thus, got a little lost the next morning? This script lets you compare two documents and see the differences between them, saving you from having to comb through nearly identical files for the slightest changes.

Indys Timer

Indys Timer
Depending on how you track time, something like this could be a lifesaver. It automatically starts when you open a document and stops when you close it. It’s available as a limited free version, or you can pick up the commercial version.

MakeCropMarks.jsx

MakeCropMarks.jsx
Occasionally, you’ll have to set up your own job for printing, at the very least to give the prepress operator a sense of what you’re aiming for. This script adds crop marks, with options for length, offset, bleed, stroke weight and more.

Print Tools Library

Print Tools Library
Here is a collection of printing aids (for color bars, registration marks, crop marks, fold marks and trim marks). Just drag and drop where needed.

Convert All Text to Outlines

Convert All Text to Outlines
Some printers still require text to be outlined before going to press. Rather than go through it page by page, you can just use this script, which outlines all text in the document and puts it on a separate layer.

IndexMatic

IndexMatic
Setting up an index can be incredibly laborious. IndexMatic makes the process much easier, with its collection of powerful features and varied options. Boasting an impressive amount of documentation and help, the script will grow on you quickly.

Panel-Based Web Browser

Panel Based Web Browser for InDesign CS5
All too often, you’ll need to load a Web browser to grab some content, verify some information or find a placeholder image. But getting off track in your usual browsing environment is easy. This plugin will keep you focused on the task at hand by opening up a browser window with InDesign’s palette.

Interactive Shortcuts Guide

Interactive Shortcuts Guide
InDesign is simple to work with, but learning all of the shortcuts can be complicated and time-consuming. This interactive guide is worth bookmarking; regular visits to it will help you learn the shortcuts to routine tasks.

Last Click

Tetris for InDesign

Tetris for InDesign
With all the time you’re now saving with these plugins and scripts, why not play a little Tetris in InDesign?

Conclusion

InDesign is a tool like no other in Adobe’s Creative Suite. While features are added to each version of Illustrator and Photoshop to help you create more varied kinds of graphics, InDesign seems to be focusing on streamlining and making the designer’s work easier. It is, then, as much design should be: quiet and out of the way. It’s seemed to me to always lie in the shadow as we apply our design and communication skills to the blank pages before us, keeping all of the best features accessible with a few key strokes.
We’re hoping that with these plugins and scripts, InDesign will become even easier, and quieter, for you to use, helping you to focus on the design at hand, rather than on the tool you’re using to bring it to life.