gpt4 book ai didi

Javascript 自动加载图像脚本不起作用

转载 作者:行者123 更新时间:2023-12-03 11:09:31 24 4
gpt4 key购买 nike

滚动时加载照片不起作用

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/

最佳答案

您缺少一些右大括号。我建议使用与您的大括号相匹配并格式化您的代码的文本编辑器,以最大限度地减少此类错误。

我认为你的函数应该是这样的:

 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!
}

关于Javascript 自动加载图像脚本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27675726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com