更多操作
无编辑摘要 |
无编辑摘要 |
||
(未显示同一用户的3个中间版本) | |||
第3行: | 第3行: | ||
$(this).attr('id','collapsed-'+i) | $(this).attr('id','collapsed-'+i) | ||
$(this).attr('defheight',$('.data-folded').height()) | $(this).attr('defheight',$('.data-folded').height()) | ||
$(this).bind('click',function(){ | $(this).children('.collpased-title').bind('click',function(){ | ||
toggleCollapse('#collapsed-'+i) | toggleCollapse('#collapsed-'+i) | ||
}) | }) | ||
第13行: | 第13行: | ||
closeSpeed = closeSpeed !== undefined ? closeSpeed : 'fast' | closeSpeed = closeSpeed !== undefined ? closeSpeed : 'fast' | ||
selector = $(selector) | selector = $(selector) | ||
var defaultHeight = selector.attr('defheight') | var defaultHeight = selector.attr('defheight')*1 | ||
var paddingHeight = 10 | var paddingHeight = 10 | ||
var targetHeight = defaultHeight + paddingHeight + selector.children('.collpased-content').height() | var targetHeight = defaultHeight + paddingHeight + selector.children('.collpased-content').height() | ||
console.log(defaultHeight,targetHeight) | |||
var currentHeight = selector.height() | var currentHeight = selector.height() | ||
if(defaultHeight === currentHeight){ | if(defaultHeight === currentHeight){ |
2023年2月11日 (六) 16:46的最新版本
function bindCollpase() {
$('.collpased-container').each(function (i,v) {
$(this).attr('id','collapsed-'+i)
$(this).attr('defheight',$('.data-folded').height())
$(this).children('.collpased-title').bind('click',function(){
toggleCollapse('#collapsed-'+i)
})
})
}
function toggleCollapse(selector, openSpeed, closeSpeed){
openSpeed = openSpeed !== undefined ? openSpeed : 'fast'
closeSpeed = closeSpeed !== undefined ? closeSpeed : 'fast'
selector = $(selector)
var defaultHeight = selector.attr('defheight')*1
var paddingHeight = 10
var targetHeight = defaultHeight + paddingHeight + selector.children('.collpased-content').height()
console.log(defaultHeight,targetHeight)
var currentHeight = selector.height()
if(defaultHeight === currentHeight){
selector.animate({
height: targetHeight
}, openSpeed,function () {
selector.removeClass('data-folded')
selector.css('height','auto')
});
}else {
selector.animate({
height: defaultHeight
}, closeSpeed);
selector.addClass('data-folded')
}
}
function tollgeAllCo(){
$('.collpased-a').each(function () {
$(this).click()
})
}
bindCollpase()