GithubHelp home page GithubHelp logo

upyachka.js's Introduction

upyachka.js

UPYACHKA, web page disease. Symptoms: the page with images jerks and jumps around during loading. Long pages with large photos are often susceptible to upyachka.

Page has upyachka

It happens when browser doesn’t know the dimensions of images and cannot reserve space for them as it contructs the page.

Medieval medicine

Earlier it was treated by simply specifying the width and height:

<img src="smile.jpg" width="900" height="600" />

Page is cured of upyachka

Still sick

Today in the responsive era it’s not enough. Quite often we want images to be rubber and add something like this:

img {
  max-width: 100%;
  height: auto;
}

Pictures become responsive, okay. But because of height:auto browser must download the images to calculate their size and cannot reserve the appropriate space to it beforehand. Upyachka again here. Despite the specified width and height.

Recipe

To cure upyachka, I wrote a tiny vanilla plugin that takes width and height attributes and calculates the size of every responsive image until browser fully loaded and handled them.

Please check the examples:

To cure your pages add the following to the <head> of your page:

<script src="/path/to/upyachka.min.js"></script>

Specify both the height and width attributes for images.

Now the layout should be fixed and the images will pop into place when loaded.

Placehold loading images with background using temporary upyachka class:

img.upyachka {
  background-color: #f3f3f3;
}

2014, Artem Polikarpov

upyachka.js's People

Contributors

artpolikarpov avatar

Watchers

 avatar

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.