我有一个滚动 div,当您水平滚动时,它会通过 API 的 ajax 和 json 加载数据。
我目前可以使用它,但我遇到的问题是我在一个页面上有多个滚动 div。我需要让 jquery 知道正在滚动的 div 的 ID,以便 ajax 可以使用不同的 API 调用将正确的数据加载到该特定的 div。
这是我的代码的 HTML:
<div id="ip-technology" class="scroll-box">
<h2>Latest Videogames Titles</h2>
<a class="view" href="technology.html">See all</a>
<ul class="scroll-horizontal mCustomScrollbar _mCS_3">
<div class="mCustomScrollBox mCSB_horizontal" id="mCSB_3" style="position:relative; height:100%; overflow:hidden; max-width:100%;"><div class="mCSB_container" style="position: relative; left: 0px; width: 6721px; ">
<li class="product-Magazine">
<a href="#">
<span class="store-badge"></span>
<img src="cover.jpg" width="124" height="166">
</li>
</div>
<div class="mCSB_scrollTools" style="position: absolute; display: block; ">
<div class="mCSB_draggerContainer" style="position:relative;">
<div class="mCSB_dragger ui-draggable" style="position: absolute; width: 149px; ">
<div class="mCSB_dragger_bar" style="position:relative;">
</div></div><div class="mCSB_draggerRail"></div>
</div></div></div>
</ul>
这里是 jquery/ajax...
$(".scroll-horizontal").mCustomScrollbar({
horizontalScroll:true,
scrollEasing:"easeOutBack",
advanced:{
autoExpandHorizontalScroll: true
},
callbacks:{
onTotalScrollOffset: 30,
onTotalScroll: function(){
var url = 'http://www.URL-TO-API.com' //Needs to somehow pass in the div id
$.ajax({
type: 'GET',
url: url,
async: true,
jsonpCallback: 'callback',
dataType: 'jsonp',
success: function(data)
{
$.each(data.products, function(key, val)
{
if (loadNumber <= 4) {
$('li.loading').before('<li class="product-ebook"><a href="product.html"><span class="store-badge"></span><img src="'+val.image+'" width="124" height="166" /><h3>'+val.title+'</h3></a></li>');
};
if (loadNumber >= 4) {
$('li.loading').hide();
};
});
$('h3').html(function(index, currentHtml) {
return currentHtml.replace('Issue', '<span>Issue')
.replace('Vol', '<span>Vol');
$(this).apppend("</span>");
});
$('.scroll-horizontal').mCustomScrollbar("update");
},
error: function() {
console.log('failed');
}
});
}
}
});