从ajax加载时总是获取mCS_no_scrollbar类
Always getting mCS_no_scrollbar class when loading from ajax
我正在使用jquery CustomScrollbar插件。链接http://manos.malihu.gr/jquery-custom-content-scroller/
我正在通过ajax加载我的数据。代码如下
$(window).load(function(){
$(".top-heading-section3").mCustomScrollbar({
advanced:{
updateOnContentResize: true
}
}
);
});
当ajax完成时,我会:
$(".top-heading-section3").mCustomScrollbar('update')
但我仍然在所有div上得到mCS_no_scrollbar类,并且滚动条没有出现。
我哪里错了?
我认为问题是,在滚动条样式附加到元素之前,您可能插入了Ajax请求中的数据,然后插件错误地假设div的当前大小是设置的大小,并且在增加滚动条之前不需要滚动条。我遇到了同样的问题,我用setTimeout函数解决了它。设置要附加mCustomScrollbar的div的高度也很重要。否则,它将在添加内容时调整div的大小。
setTimeout(function(){
$('.top-heading-section3').mCustomScrollbar();
}, 600);
我将其设置为600毫秒只是为了确保它得到渲染,但您可以在测试时对其进行修改,以便在尽可能短的时间内进行渲染。
另请参阅这个链接,它也帮助我解决了我的问题。
https://github.com/malihu/malihu-custom-scrollbar-plugin/issues/237
您应该在使用ajax函数将html附加到dom后应用customrollbar。这种方式更有效、更可靠。
$.ajax({
url: "test.html",
cache: false,
success: function(html){
$(".container").append(html);
$(".top-heading-section3").mCustomScrollbar({
advanced:{
updateOnContentResize: true
}
}
);
}
});
这会很好用的。
相关文章:
- Javascript GetElementByID has no value
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- Javascript window.open()toolbar=no不起作用
- Regex表示10位数字,其中没有't允许所有零、所有单个no和序列号
- `npm install` killed for large package.json, no npm-debug.lo
- YES或NO表示对象事件中的分号
- Wordpress AJAX with raw javascript? NO Jquery
- 禁用复选框上的输入框 jquery NO onchange
- no-op if 语句会导致 Google 图表失败
- No puedo comparar una variable con un cadena de tipo String
- 在javascript中访问当前页面的页面标题[no ajax]
- JavaScript 动态更改图像 src 的位置 - NO JQuery
- RequireJs in IE8: "no define call for.."
- HTML DOMs, ids vs no ids?
- AngularJS - 在第一个可见元素上应用 CSS 类(Preferred No JQuery)
- Elasticsearch https cors已启用,但仍获得No'访问控制允许来源'标头存在于请求的
- GWT应用程序中出现错误HTTP 404(“Script Tag Failure-no status available
- PhantomJS onResourceReceived no stream
- 如何使用documet.getElementById和getElementsByClassName为display no
- 配置服务器端CORS:ExpressJS No“;访问控制允许起源”;在场