2014-12-28 41 views
0

照片負載不工作自動加載的Javascript腳本圖像不運作上滾動

SyntaxError: missing) after argument list 1:221 ReferenceError: json_loads is not defined 1:236

這裏是函數,它負載的照片和顯示網頁上

function json_loads(load_count, photo_count) { 
    $.getJSON('/json_album_detail/', { 
     'album_id': {{ object.id }}, 
     'count': photo_count, // min 3!! 
     'load_count': load_count 
     }, function(data) { 
     console.log(data); 



     for(item in data) { 
      last_item = item; 

      id = 'scrolling'; 
       console.log('Id: ' + id) 
     } 

     console.log(data.length); 
     for(i=1, count=2; i<=last_item; i++, count++) { 

      newdiv = document.createElement("div"); 
      mydiv = document.getElementById(id); 
      newdiv.className='project-img'; 
      newhref = document.createElement("a"); 
      newimg = document.createElement("img"); 
      newimg.setAttribute('src', data[i].url); 
      newhref.setAttribute('href', data[i].url); 
      newdiv.appendChild(newhref); 
      newdiv.appendChild(newimg); 
      mydiv.appendChild(newdiv); 


     } 

} 
} 

運行功能,如果滾動到下

var scroll_count = 0 
var load_count = 3 
var photo_count = 4 
$(window).on("scroll", function() { 
var scrollHeight = $(document).height(); 
console.log('scrollHeight: ' + scrollHeight); 
var scrollPosition = $(window).height() + $(window).scrollTop(); 
console.log('scrollPosition: ' + scrollPosition); 
console.log('To event = ' + (scrollHeight - scrollPosition)/scrollHeight); 
if ((scrollHeight - scrollPosition)/scrollHeight < 0.01) { 
    json_loads(load_count, photo_count); 
    scroll_count = scroll_count+1; 
    console.log(scroll_count); 
    photo_count = photo_count+1; 
    load_count = load_count+1; 
} 


}); 

測試地點:http://54.93.51.225/album/1/

回答

1

您錯過了一些右花括號。我會建議使用與您的大括號相匹配的文本編輯器並對代碼進行格式化以最大限度地減少此類錯誤

你的功能應該是這樣的,我認爲:

function json_loads(load_count, photo_count) { 
$.getJSON('/json_album_detail/', { 
    'album_id': 1, 
     'count': photo_count, // min 3!! 
    'load_count': load_count 
}, function (data) { 
    console.log(data) 
    for (item in data) { 
     last_item = item 

     id = 'scrolling' 
     console.log('Id: ' + id) 
    } 

    console.log(data.length) 
    for (i = 1, count = 2; i <= last_item; i++, count++) { 

     function spinner() { 
      document.getElementById("spinner").className = "fa fa-spinner fa fa-circle-o-notch fa-spin fa-2x"; 
     } 

     function upper() { 
      document.getElementById("spinner").className = "fa fa-chevron-circle-up fa-3x"; 
     } 

     setTimeout(spinner, 1000); 

     newdiv = document.createElement("div"); 
     mydiv = document.getElementById(id); 
     newdiv.className = 'project-img'; 
     newhref = document.createElement("a"); 
     newimg = document.createElement("img"); 
     newimg.setAttribute('src', data[i].url); 
     newhref.setAttribute('href', data[i].url); 
     newdiv.appendChild(newhref); 
     newdiv.appendChild(newimg); 
     mydiv.appendChild(newdiv); 

     setTimeout(upper, 1000); 

    } 
    }); // *** you are missing this! 
} 
+0

哦,謝謝,功能完善的工作! – Kurama