隐藏ajax附加的html直到某一点
Hide ajax appended html until certain point
我正在使用AJAX从数据库加载更多结果。
以下是基本脚本:
$('#loadmorebuilds-div').click(function() {
$.ajax({
url: 'includes/loadmorebuilds.php?type=' + type + '&pageIndex=' + pageIndex + '&st=' + searchTerm,
success: function(html) {
// append the new results
$("#buildcontainer").append(html);
// wait untill all images are loaded before the waterfall function is called
imagesLoaded( '#buildcontainer', function()
{
$("#buildcontainer").waterfall('reflow');
});
}
});
});
问题是,显示了新添加的数据(html),但它本身是重叠的,直到加载了图像,然后在容器上调用回流函数,使项目落入其网格中。
我只想在图像加载后显示附加的数据,并且项目已"回流"到瀑布网格中。
我就是不知道该怎么做。
谢谢。P.S,ImagesLoaded是一个库,用于检测何时加载所有图像,瀑布是砖石网格样式。
编辑:为了澄清,加载的html包含图像,我正在检查它们是否被加载。
隐藏更新的div,然后在加载图像时显示:
$('#loadmorebuilds-div').click(function() {
$.ajax({
url: 'includes/loadmorebuilds.php?type=' + type + '&pageIndex=' + pageIndex + '&st=' + searchTerm,
success: function(html) {
// append the new results
$("#buildcontainer").append(html).hide();
// wait untill all images are loaded before the waterfall function is called
imagesLoaded( '#buildcontainer', function()
{
$("#buildcontainer").waterfall('reflow').show();
});
}
});
});
在调用imagesLoaded回调函数之前不要附加html:
$('#loadmorebuilds-div').click(function() {
$.ajax({
url: 'includes/loadmorebuilds.php?type=' + type + '&pageIndex=' + pageIndex + '&st=' + searchTerm,
success: function(html) {
// append the new results
$("#buildcontainer").append(html).css('opacity', 0);
// wait untill all images are loaded before the waterfall function is called
imagesLoaded( '#buildcontainer', function()
{
$("#buildcontainer").waterfall('reflow').css('opacity', 1);
});
}
});
});
如何在一个空的div中添加一个类,然后在瀑布完成后添加内容。这样,只有新内容才会逐渐消失。
$('#loadmorebuilds-div').click(function() {
$.ajax({
url: 'includes/loadmorebuilds.php?type=' + type + '&pageIndex=' + pageIndex + '&st=' + searchTerm,
success: function(html) {
// append the new results
$("#buildcontainer").append('<div class="newcontent"></div>')
$("#buildcontainer").find('.newcontent').last().html(html).css('opacity', 0);
imagesLoaded( '#buildcontainer', function() {
$("#buildcontainer").waterfall('reflow').find('.newcontent').last().css('opacity', 1);
});
}
});
});
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- 如何通过ajax刷新JSF填充的javascript变量
- 如何在php文件中获取$.post-ajax传递的值
- Replacing $ .ajax?
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- Ajax发布表单序列化,发布引号'
- 通过Ajax将JavaScript函数传递给PHP文件
- ajax请求的顺序总是不同的
- 可以't使用Polymer's的核心ajax
- Ajax Live搜索发布到Laravel视图
- Ajax聊天消息重复而不仅仅是更新
- 从控制器返回后Ajax启动事件激发
- PHP AJAX图片上传示例不上传
- 从ajax请求中获取javascript对象
- 如果表格很大,我对表中元素的一点 ajax 会中断.如何解决
- 通过 $.ajax 获取数据,我怎样才能以“角度”的方式做到这一点.$http取代 $.ajax 吗?
- 有没有AJAX框架可以做到这一点
- 隐藏ajax附加的html直到某一点
- 在Ajax调用中指定用户代理,如何正确地做到这一点
- 带有PHP,JS/jQuery和一点AJAX的CRUD方法