1

I have this code in html:

echo '<div class="sponsors__item-bg-img lazy-load" data-original="'.$sponsor_item['image'].'" style="background-image: url();" src="https://static.questex.asia/template7/images/grey.gif" ></div></a>';

And the jquery.lazyload.js got this part:

$self.one("appear", function() {
            if (!this.loaded) {
                if (settings.appear) {
                    var elements_left = elements.length;
                    settings.appear.call(self, elements_left, settings);
                }
                $("<img />")
                    .bind("load", function() {

                        var original = $self.attr("data-" + settings.data_attribute);
                        $self.hide();
                        if ($self.is("img")) {
                            $self.attr("src", original);
                        } else {
                            $self.css("background-image", "url('" + original + "')");
                        }
                        $self[settings.effect](settings.effect_speed);

                        self.loaded = true;

                        /* Remove image from array so it is not looped next time. */
                        var temp = $.grep(elements, function(element) {
                            return !element.loaded;
                        });
                        elements = $(temp);

                        if (settings.load) {
                            var elements_left = elements.length;
                            settings.load.call(self, elements_left, settings);
                        }
                    })
                    .attr("src", $self.attr("data-" + settings.data_attribute));
            }
        });

However, the final result is the image is not loaded, because the url is not added by the js:

<div class="sponsors__item-bg-img lazy-load" data-original="https://img.questex.asia/sites/default/files/styles/219x164/public/BizProLogo.jpg?itok=KLf9ojX0&amp;timestamp=1527822985" style="background-image: url();" src="https://static.questex.asia/template7/images/grey.gif"></div>

Anyone know how can i check what happened or how should i resolve the problem? Thanks.

4
  • Firstly note that bind() was deprecated a long time ago. on() is the preferred method now. Check you're using an up to date version of jQuery. With regard to the issue, use console.log(original) in the load event handler to check what the value is. It would appear to be empty. If that's the case check what the data attribute you're reading holds at runtime. Commented Jun 1, 2018 at 9:13
  • I am using jquery-3.1.1.min.js and updated the lazyload to cdnjs.cloudflare.com/ajax/libs/vanilla-lazyload/10.5.2/…, but still the same. And how can i check the data attribute at runtime? Commented Jun 1, 2018 at 9:30
  • Use console.log() to check what its value is Commented Jun 1, 2018 at 9:30
  • The result of console.log(original) is here drive.google.com/open?id=1f6tPxsuPxU7Tepp_WPu3a9k8FDmZSqtM Commented Jun 1, 2018 at 9:44

0

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.