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');                    

            }
        });
2

3 Answers 3

8
+50

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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');

  }
});

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.