thinker3197 / progressively

A JavaScript library to load images progressively 🌇
https://thinker3197.github.io/progressively
MIT License
698 stars 68 forks source link

The img tag generated by native javascript does not seem to work #37

Closed ticks-tan closed 3 years ago

ticks-tan commented 3 years ago

The img tag generated by native javascript does not seem to work.

ticks-tan commented 3 years ago

This is my main code.

Generate img tag code `function LoadPictures(url1,url2,parentid) {
var skip = 0;

    while (skip < 320)
    {
        var url = url1 + skip + url2;
        mdui.$.ajax({
            method: 'GET',
            url: url,
            success: function (data) {
                var json = JSON.parse(data);
                var jsonary = json['res'];
                var jsonary1 = jsonary['vertical'];
                var mparent = document.getElementById(parentid);
                for (var i in jsonary1)
                {
                    var img = jsonary1[i].img;
                    var pa = document.createElement('figure');
                    pa.setAttribute("class","progressive");
                    mparent.appendChild(pa);
                    var image = document.createElement("img");
                    image.setAttribute("data-progressive",img);
                    image.setAttribute("data-progressive-sm",img);
                    image.setAttribute("class","progress__img");
                    image.classList.add("progress--not-loaded");
                    image.style.marginTop = "5px";
                    image.src = img;
                    image.addEventListener('click', function(){
                        var dialog = new mdui.Dialog("#Dialog_Picture");
                        document.getElementById("dialog_picture").src = this.src;
                        dialog.open();
                    })
                    pa.appendChild(image);
                }
            }
        });
        skip = skip + 30;
    }    
}`

Initialization code <script type="text/javascript"> window.progressively.init(); </script>