Ahmet Zeybek
Ahmet Zeybek

Reputation: 1224

How can we make this preloader while loading elements in page

This image from LinkedIn, Facebook, Discord etc. is using this preloader effect, i have found this: http://cloudcannon.com/deconstructions/2014/11/15/facebook-content-placeholder-deconstruction.html

But there is no more post about this I couldn't find

enter image description here

Upvotes: 0

Views: 5291

Answers (1)

Junius L
Junius L

Reputation: 16122

Load the placeholder and get data from the server, after getting data from the server hide the placeholder.

// using timeout to illustrate a delay
    setTimeout(function () {
        $('.timeline-wrapper').hide();
        $('.show-data').show();
    }, 3000);

//    get your data from server here
//    $.post('getdata.php', function (data) {
//        // process your data here
//       hide placeholder
//       $('.timeline-wrapper').hide();
//    })
.timeline-item {
            background: #fff;
            border: 1px solid;
            border-color: #e5e6e9 #dfe0e4 #d0d1d5;
            border-radius: 3px;
            padding: 12px;

            margin: 0 auto;
            max-width: 472px;
            min-height: 200px;
        }

        @keyframes placeHolderShimmer {
            0% {
                background-position: -468px 0
            }
            100% {
                background-position: 468px 0
            }
        }

        .animated-background {
            animation-duration: 1s;
            animation-fill-mode: forwards;
            animation-iteration-count: infinite;
            animation-name: placeHolderShimmer;
            animation-timing-function: linear;
            background: #f6f7f8;
            background: linear-gradient(to right, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
            background-size: 800px 104px;
            height: 96px;
            position: relative;
        }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="timeline-wrapper">
    <div class="timeline-item">
        <div class="animated-background">
            <div class="background-masker header-top"></div>
            <div class="background-masker header-left"></div>
            <div class="background-masker header-right"></div>
            <div class="background-masker header-bottom"></div>
            <div class="background-masker subheader-left"></div>
            <div class="background-masker subheader-right"></div>
            <div class="background-masker subheader-bottom"></div>
            <div class="background-masker content-top"></div>
            <div class="background-masker content-first-end"></div>
            <div class="background-masker content-second-line"></div>
            <div class="background-masker content-second-end"></div>
            <div class="background-masker content-third-line"></div>
            <div class="background-masker content-third-end"></div>
        </div>
    </div>
</div>
<div class="show-data" style="display: none">
  <p>data from server</p>
</div>

Upvotes: 1

Related Questions