jScrollPane 和 AJAX
我正在尝试通过 AJAX 调用 PHP 脚本加载一些数据,然后返回它,等等。好吧,它工作得很好,直到 jScrollPane 不会在 AJAX 调用上重新加载。我根本不明白为什么,因为我在 $.ajax 调用的成功部分中调用了它......但是哦,好吧,不知道。看看下面的代码并告诉我我做错了什么/如何修复它。
function eventLink(){
jQuery(".ticket-link a").fancybox({
width:710,
height:750,
type:"iframe",
transitionIn:"elastic",
transitionOut:"elastic",
speedIn:600,
speedOut:600,
easingIn:"easeInExpo",
easingOut:"easeOutExpo",
overlayShow:true,
hideOnOverlayClick:false,
hideOnContentClick:false,
overlayOpacity:0.8,
overlayColor:"#000",
showCloseButton:true,
titleShow:true,
centerOnScroll:true
});
}
function scrollPane() {
jQuery('.scroll-pane').jScrollPane({
showArrows: true,
autoReinitialise: true
});
}
jQuery(document).ready(function(){
jQuery("select[name='sortby']").change(function(){
var a=jQuery(this).val();
jQuery.ajax({
type:"GET",
url:"ticket_order.php",
data:"sortby="+a,
beforeSend:function(){
jQuery("#ajax-loader").show();
jQuery("#ticket-list").hide(200);
jQuery("#ticket-list").empty()},
complete:function(){
jQuery("#ajax-loader").hide();
eventLink();
},
success:function(a){
jQuery("#ticket-list").html(a);
jQuery("#ticket-list").show(200);
scrollPane();
}
});
return false});
eventLink();
scrollPane();
});
I'm trying to load some data via an AJAX call to a PHP script and then returning it, bla bla bla. Well, it works all fine till jScrollPane won't reload on the AJAX call. I simply don't understand why, since I've called it in the success part of the $.ajax call... But oh well, dunno. Have a look at the code below and tell me what I'm doing wrong/how to fix it.
function eventLink(){
jQuery(".ticket-link a").fancybox({
width:710,
height:750,
type:"iframe",
transitionIn:"elastic",
transitionOut:"elastic",
speedIn:600,
speedOut:600,
easingIn:"easeInExpo",
easingOut:"easeOutExpo",
overlayShow:true,
hideOnOverlayClick:false,
hideOnContentClick:false,
overlayOpacity:0.8,
overlayColor:"#000",
showCloseButton:true,
titleShow:true,
centerOnScroll:true
});
}
function scrollPane() {
jQuery('.scroll-pane').jScrollPane({
showArrows: true,
autoReinitialise: true
});
}
jQuery(document).ready(function(){
jQuery("select[name='sortby']").change(function(){
var a=jQuery(this).val();
jQuery.ajax({
type:"GET",
url:"ticket_order.php",
data:"sortby="+a,
beforeSend:function(){
jQuery("#ajax-loader").show();
jQuery("#ticket-list").hide(200);
jQuery("#ticket-list").empty()},
complete:function(){
jQuery("#ajax-loader").hide();
eventLink();
},
success:function(a){
jQuery("#ticket-list").html(a);
jQuery("#ticket-list").show(200);
scrollPane();
}
});
return false});
eventLink();
scrollPane();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在使用 jScrollPane 时遇到了这个问题。一旦它在元素周围创建了滚动窗格结构,您就需要以不同的方式对待它。它对在您的函数中重新初始化的反应不佳。相反,您必须获取 api 的引用并通过公开的方法重新初始化。
使用您的代码的一个示例是...
然后您的 jScrollpane 需要两件事。这就是内容容器和重新初始化方法。原因似乎是,一旦使用 jScrollPane() 初始化容器,容器本身就变成了 jScrollpane 对象。内容被移动到该对象内的容器中。因此,如果替换目标 div 的内容,您将删除组成 jScrollPane 对象的 html 元素。以下是获取内容窗格、填充数据并重新初始化的调用。
api.getContentPane() 将为您提供对滚动窗格业务端的引用,而 api.reinitialise() 将重绘并重新计算滚动窗格。因此,要使用您的示例,
将变为:
This
Here is the api 的最佳文档寻找。
I've run into this problem with jScrollPane. Once it creates the scrollpane structure around an element, you need to treat it differently. It doesn't respond well to being re-initialized as in your function. Instead, you have to get a reference to the api and reinitialise through the exposed method.
An example using your code would be...
Then there are two things you need for your jScrollpane. That's the content container and the reinitialise method. The reason seems to be that once you initialise a container with jScrollPane(), the container itself becomes a jScrollpane object. The content is moved to a container within that object. So if you replace the contents of the target div, you'll remove the html elements that make up a jScrollPane object. Here are the calls to get you the content pane, fill it with data and reinitialise it.
api.getContentPane() will get you a reference to the business end of your scroll pane and api.reinitialise() will redraw and recalculate the scrollpane. So to use your example,
would become:
This
Here is the best documentation of the api as I could find.