如何仅从父级而不是子级销毁 slimScroll
How to destroy the slimScroll only from parent not from children
我想销毁具有以下条件的 slimScroll
,它工作正常。
但问题是这也会从子项中删除所有 slimScroll
对象。
所以,parent 和 children 都被销毁了,如何避免?
这是我的条件,我没有使用 id
我在这里使用 class
选择器。
if(this.spaceFinder(this.clippings) < this.clippings.innerHeight() ) {
this.clippings.slimScroll({destroy:true});
//remove from all childrens too..
}
我试过这个方法,成功了!
var container = $('.container');
var para = $('.textInfo');
$('#add').click(function () {
var textarea = $('<textarea />');
textarea.text(para.text());
textarea.appendTo('.container');
textarea.slimScroll({height:'50px'});
if(container[0].scrollHeight > 300) {
container.slimScroll({height:'200px'});
}
});
$('#remove').click(function () {
$('textarea').first().slimScroll({destroy:true});
$('textarea').first().remove();
if(container[0].scrollHeight < 300) {
var children = $('#container').children();
$('#container').parent().replaceWith($('#container'));
}
});
@3gwebtrain,我修复了插件。
我提出了拉取请求:https://github.com/rochal/jQuery-slimScroll/pull/193
如果您想更改 jquery.slimscroll.js 文件,修复方法很简单。您可以在此处查看所做的修改:https://github.com/rochal/jQuery-slimScroll/pull/193/files
我想销毁具有以下条件的 slimScroll
,它工作正常。
但问题是这也会从子项中删除所有 slimScroll
对象。
所以,parent 和 children 都被销毁了,如何避免?
这是我的条件,我没有使用 id
我在这里使用 class
选择器。
if(this.spaceFinder(this.clippings) < this.clippings.innerHeight() ) {
this.clippings.slimScroll({destroy:true});
//remove from all childrens too..
}
我试过这个方法,成功了!
var container = $('.container');
var para = $('.textInfo');
$('#add').click(function () {
var textarea = $('<textarea />');
textarea.text(para.text());
textarea.appendTo('.container');
textarea.slimScroll({height:'50px'});
if(container[0].scrollHeight > 300) {
container.slimScroll({height:'200px'});
}
});
$('#remove').click(function () {
$('textarea').first().slimScroll({destroy:true});
$('textarea').first().remove();
if(container[0].scrollHeight < 300) {
var children = $('#container').children();
$('#container').parent().replaceWith($('#container'));
}
});
@3gwebtrain,我修复了插件。
我提出了拉取请求:https://github.com/rochal/jQuery-slimScroll/pull/193
如果您想更改 jquery.slimscroll.js 文件,修复方法很简单。您可以在此处查看所做的修改:https://github.com/rochal/jQuery-slimScroll/pull/193/files