Scene: Do a mobile Web page, when the scan to enter the page needs to determine whether users choose to share the circle of friends, if you want to share a friend circle, you need to find out the page class=article_content of a div below all the IMG pictures, if the picture proportion appropriate (aspect scale), Then set it to the thumbnail display on the left side of the share.
functionGetThumbnail () {varArrayimgs = []; $("Div.article_content img"). each (function () { //Alert ($ (this). attr ("src"));Arrayimgs.push ($ ( This). attr ("src")); }); varwidth, height, i; varResult= ""; for(i = 0; i < arrayimgs.length; i++) { //Image Address varImg_url =Arrayimgs.pop (); //Creating Objects varIMG =NewImage (); //change the src of the pictureIMG.SRC =Img_url; //determine if there is a cache if(img.complete) {//PrintAlert (' from:complete:width: ' + img.width + ', Height: ' + img.height + '; Result: "+result); }Else{ //load Complete ExecutionImg.onload =function(){ //PrintAlert (' from:onload:width: ' + img.width + ', Height: ' + img.height + '; Result: "+result); }; } if(Img.width/img.height > 0.6 && img.height/img.width < 1.4) {result=Img_url; Break; } } returnresult;}
Get thumbnails from a Web page when sharing to a friend's circle