/* --- 底部链接菜单 --- */ $(document).ready(function() { // 按钮宽度 var btnW = $('.friend-link .btn').width(); // 获取下拉菜单 var menu = $('.friend-link .menu'); // 获取li内部a标签的真实宽度 var realW = menu.find('a').css('margin-left'); // 自动调整下拉菜单宽度 // menu.css('width',btnW); menu.find('a').css('width',btnW-parseInt(realW)+'px'); // 下拉菜单隐藏 $('.friend-link .menu').hide().animate({height:0},500); // 按钮点击事件 $('.friend-link .btn').click(function(e) { if ( e && e.stopPropagation ){ e.stopPropagation(); }else { window.event.cancelBubble = true; return false; } if ( e && e.preventDefault ) { e.preventDefault(); }else{ window.event.returnValue = false; return false; } // 获取父元素同级索引 var index = $(this).parent().index()-1; // 获取当前点击菜单 var thisMenu = $(this).next(); // 结束动画,避免不停 thisMenu.stop(false,true); for (var i = 0; i < $('.friend-link .select').length; i++) { // 判断除当前点击外的元素隐藏 if(index == i) continue; // 隐藏 $('.friend-link .select:eq('+i+') .menu').animate({height:0},500,function(){$(this).hide()}); } if(thisMenu.css('display') == 'none') { // 先将元素显示 thisMenu.show(); // 获取li整体的高度就是菜单高度 var liChild = $(this).next().children(); var menuHeight = liChild.length * liChild.height(); thisMenu.animate({height:menuHeight},500); }else{ // 下拉完成后隐藏 //thisMenu.animate({height:0},500,function(){$(this).hide()}); } }); $('.close').on('click', function(e) { $('.friend-link .menu').animate({height:0},1000,function() { $(this).hide(); }); }); });