Snapchat using Javascript – Zuck.js

Stories! Stories are everywhere these days. Snapchat, Instagram, Facebook, Facebook Messenger and Whatsapp all have stories. Hell, it’s only a matter of time before Microsoft Excel gets a stories update.



In any case, if you want to build an app like Snapchat or build an app like Instagram, there is an easy way to do so. The focus of this tutorial will be about building the story functionality of Snapchat and Instagram into an app. We’ll save the whole disappearing message thing for a later date.

Okay, so you might be thinking that this is going to be a whole lot of work. Guess what? It’s not. This is all thanks to an amazing open source library on GitHub called Zuck.js.


Zuck.js is a javascript library that easily allows you to add stories into an app. It already comes ready to handle opening stories, cube animation effects and giving you the clean Instagram or Snapchat look. It really makes building stories super easy to do! So because this is a javascript library, we are going to build a webapp that can run in the phone’s browser. It’s going to be very basic and look something like this:




Setting up the HTML

To get started, let’s create a basic HTML file:




<metaname=“viewport"content=“width=device-width, initial-scale=1”>






Make sure that you download the Zuck js library and placed it somewhere in your project structure so that you can link to it. In this HTML file, I linked to the Zucks CSS stylesheet and the Zuck skin that I want to use. Inside the body, the only thing that I need is a div. This div will be passed to Zuck so that it can render the stories to it. Finally, I imported the Zuck javascript library then my main javascript code.

The Javascript

Now, in my main js file, I start by defining a function that will return an object with the properties specified:

// Using object short-hand (id: id)

return {












In that function, I pass in a whole bunch of parameters. It then outputs an object with those parameters. Keep in mind, I am using the property shorthand. So instead of saying {id: id} it&#8217;s just {id}.

Next, initialize the Zuck library with the below code:


const stories = new Zuck(‘stories’, {








stories: [],



When initializing the Zuck object, make sure that the &#8216;stories&#8217; parameter matches the div id that you defined in your HTML. Afterwards, I just loaded the Zuck library with the skin I wanted and also passed in a couple of options. You can find all the available options outlined in the Zuck readme.

Finally, let&#8217;s add a story to the story array. Inside of the array, add the following object:


stories: [



photo:‘' ,




items: [

buildItem(‘1’, ‘photo’, 3, ‘' , ‘’, false, 1492665454),

buildItem(‘2’, ‘photo’, 3, ‘' , ‘’, ‘’, false, 1492665454),

buildItem(‘3’, ‘video’, 0, ‘' , ‘' , ‘’, false, 1492665454),




This essentially will build a single story that contains three items. The items can be a mixture of photos or videos. You can also adjust the length of each story item. Zuck js works just like Snapchat and Instagram. So if the user has already seen the story (hence the seen boolean) it will automatically proceed to the next item.

So now you have everything you need for your basic Snapchat app. If you open up your Index.html file in the browser, you should see the single story listed. Clicking on it will open up the story in a viewer. From this point, you could make it more dynamic by pulling in stories from a REST endpoint or the user&#8217;s gallery if you wanted. To get this on Android or iOS simply wrap the app in a webview.

<a href="" target="_blank" rel="noopener">You can download the full code on Github</a>