注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
function bindCollpase() {
$('.collpased-container').each(function () {
$(this).children('.collpased-head').after('<a href="#" class="collpased-a">▼点击展开▼</a>')
$(this).children('.collpased-a').bind('click',{t:$(this)},function (event) {
toggleCollapse(event.data.t)
})
})
}
function openAllCollapse(){
$('.collpased-container').each(function () {
openCollapse($(this))
})
}
function openCollapse(obj){
var temp = $('<div class="collpased-temp"></div>')
temp.html(obj.children('.collpased-content').html())
temp.css('display','none')
temp.appendTo(obj)
var defHeight = $('.collpased-temp').height()
var slideHeight = 0;
var curHeight = obj.children('.collpased-content').height();
var move = 3+obj.children('.collpased-head').height()/2
console.log(curHeight)
if(curHeight===slideHeight){
obj.addClass('blue-border')
obj.children('.collpased-a').css('display','none')
obj.children('.collpased-head').animate({
top: '-='+move+'px',
}, "normal");
obj.children('.collpased-content').animate({
height: defHeight
}, "normal");
obj.children('.collpased-a').html('▲点击收起▲');
obj.children('.collpased-a').fadeIn('fast')
}
}
function closeAllCollapse(){
$('.collpased-container').each(function () {
closeCollapse($(this))
})
}
function closeCollapse(obj){
var temp = $('<div class="collpased-temp"></div>')
temp.html(obj.children('.collpased-content').html())
temp.css('display','none')
temp.appendTo(obj)
var defHeight = $('.collpased-temp').height()
var slideHeight = 0;
var curHeight = obj.children('.collpased-content').height();
var move = 3+obj.children('.collpased-head').height()/2
console.log(curHeight)
if(curHeight!==slideHeight){
obj.children('.collpased-a').css('display','none')
obj.removeClass('blue-border')
obj.children('.collpased-head').animate({
top: '+='+move+'px',
border: '1px solid red'
}, "normal");
obj.children('.collpased-content').animate({
height: slideHeight
}, "normal");
obj.children('.collpased-a').html('▼点击展开▼');
obj.children('.collpased-a').fadeIn('fast')
}
}
function toggleCollapse(obj){
var temp = $('<div class="collpased-temp"></div>')
temp.html(obj.children('.collpased-content').html())
temp.css('display','none')
temp.appendTo(obj)
var defHeight = $('.collpased-temp').height()
var slideHeight = 0;
var curHeight = obj.children('.collpased-content').height();
var move = 3+obj.children('.collpased-head').height()/2
console.log(curHeight)
if(curHeight===slideHeight){
obj.addClass('blue-border')
obj.children('.collpased-a').css('display','none')
obj.children('.collpased-head').animate({
top: '-='+move+'px',
}, "normal");
obj.children('.collpased-content').animate({
height: defHeight
}, "normal");
obj.children('.collpased-a').html('▲点击收起▲');
obj.children('.collpased-a').fadeIn('fast')
}else {
obj.children('.collpased-a').css('display','none')
obj.removeClass('blue-border')
obj.children('.collpased-head').animate({
top: '+='+move+'px',
border: '1px solid red'
}, "normal");
obj.children('.collpased-content').animate({
height: slideHeight
}, "normal");
obj.children('.collpased-a').html('▼点击展开▼');
obj.children('.collpased-a').fadeIn('fast')
}
$('.collpased-temp').remove()
}
function tollgeAllCo(){
$('.collpased-a').each(function () {
$(this).click()
})
}
bindCollpase()