0

How to add loader for image on page load .. I want to add loader until the main image is ready on page load.

how to do this

Thanks

Update:

<div class="outer-box">
    <nav class="social">
        <div class="box">
            <p>Showing a display Loading Icon Until the Page Loads Completely..</p>
            <img id="new" class="main-img" src="http://magento/pub/media/images/sizechart/babydoll.png"/></div>

    </nav>
</div>
<script>
    require([
        'jquery'
    ], function ($) {
        $(document).ready(function(){alert("sdfsdf");

            // show loading image
             $('body').trigger('processStart');

            // main image loaded
            $('.main-img').on('load', function(){
                // hide the loading image
                $('body').trigger('processStop');
            });
        });
</script>
1
  • where you have the loader image? Feb 21, 2019 at 6:52

1 Answer 1

0

Try the below jquery code :

// show loading image
$('.loader_image_class').show();

// main image loaded
$('.main_image_class').on('load', function(){
  // hide the loading image
  $('.loader_image_class').hide();
});
4
  • its not working
    – Mahi M
    Feb 21, 2019 at 6:42
  • Getting any error in console? Feb 21, 2019 at 6:43
  • No ... ........
    – Mahi M
    Feb 21, 2019 at 6:44
  • Can you share your code and where you adding this code? Feb 21, 2019 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.