Coder Social home page Coder Social logo

knockoutjs-load's Introduction

KnockoutJS example code to show a CSS spinner before loading rest of the page, scripts and data. This is done without flickering (showing part of markup that is meant to be used as KnockoutJS template).

How it works

Page loading flow:

  • Browser loads page up to the spinner
  • Browser displays the spinner
  • Browser loads rest of page, including scripts
  • Part of page used for KnockoutJS template is not shown
  • Scripts load some data
  • KnockoutJS model is bound
  • View is rendered and the spinner is automatically hidden

Spinner is wrapped into conditional KnockoutJS tags. These tags have no effect until ko.applyBindings is called:

<!-- ko if: false -->
    <div class="loader"></div>
<!-- /ko -->

Once ko.applyBindings is called, the conditional tags become active and the loader spinner element is removed from the page DOM by KnockoutJS.

Rest of the page is wrapped into element that has CSS property display: none set by a class hide. This hides the content until the class is removed:

<div data-bind="css: { hide: false }" class="hide">
    Message: <span data-bind="text: message"></span>
</div>

The class is automatically removed when bindings are applied by ko.applyBindings. This is achieved through the built-in css binding.

CSS spinner code was taken from http://projects.lukehaas.me/css-loaders/.

Demo

Visit http://demos.rlaanemets.com/knockoutjs-load/.

License

The MIT License.

knockoutjs-load's People

Contributors

rla avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

marcosdsdba

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.