6

I'm using this plug in jQuery Lazy - Delayed Content, Image and Background Lazy Loader

I'm trying to add image border-color and image border thickness to the image after lazy loading but it seems like it has no effect. If I press "inspect" at developer console, I can see this attributes are added to image style but its effect is not shown on screen.

HTML

<img class="lazy" data-src= "{{ individual_image.url }}" src="{% static 'img/image_loading.jpg' %}"style="opacity:0.3; width:150px; height:150px;>

JQuery

        $('img.lazy').Lazy({

            scrollDirection: 'vertical',                
            visibleOnly: false,               
            afterLoad: function(element) {                   
                element.css('border-width', 'thick');
                element.css('border-color', 'chartreuse');                    

            }
        });
Alexandre Elshobokshy
  • 10,720
  • 6
  • 27
  • 57
Bih Cheng
  • 655
  • 1
  • 13
  • 28

3 Answers3

8

Border-style CSS attribute is required. Default value is none, so border is not displayed.

$('img.lazy').Lazy({
    scrollDirection: 'vertical',                
    visibleOnly: false,               
    afterLoad: function(element) {                   
        element.css('border-width', 'thick');
        element.css('border-color', 'chartreuse');
        // add border-style and border becomes visible                    
        element.css('border-style', 'solid');
    }
});

Live demo

userlond
  • 3,632
  • 2
  • 36
  • 53
8

I would suggest doing it this way :

    $('img.lazy').Lazy({

        scrollDirection: 'vertical',                
        visibleOnly: false,               
        afterLoad: function(element) {                   
            element.css('border', 'thick solid chartreuse');                  

        }
    });

By using border you won't be missing any parameters! :) Also less code to do the same thing is always better.

I prepared a demo with a large file and a loading animation so you could actually notice the lazy loading before the image loads and the border takes effect.

JSFiddle demo

Alexandre Elshobokshy
  • 10,720
  • 6
  • 27
  • 57
1

You can use the border attribute only and set it like below

$('img.lazy').Lazy({

  scrollDirection: 'vertical',
  visibleOnly: false,
  afterLoad: function(element) {
    element.css('border', 'width style color');

  }
});