$(function() { // 自定义 select (function () { var selects = $("#left .divselect"); if (!selects.length) return; selects.each(function(idx) { var elem = $(this), idx = elem.index(), cptn = elem.find('.caption'), ul = elem.find('ul'), slct = elem.find('select'), optn = elem.find('option'), duration = 150, opened = false, tt = -1, isuser = $('#volunteer .user').length === 1; offset_on = isuser? -54: -51, offset_off = isuser? -3: 0; if (!slct.length) return; ul.children().eq(0).addclass('on'); elem.on('mousedown', function(e, target) { if (opened) { target = geteventtarget(e); if (target.nodename === "span") return; if (target.nodename === "li") target.classname = "on"; cptn.text(geteventtargettext(target)); optn.val(target.getattribute('data-value')); close(); } else { open(); } }).hover(function() { cleartimeout(tt); },function() { if (!opened) return; tt = settimeout(close, 500); }); function open() { cptn.stop().animate({'background-position-y':offset_on}, duration); ul.stop().slidedown(duration, statetoggle); } function close() { cptn.stop().animate({'background-position-y':offset_off}, duration); ul.stop().slideup(duration, statetoggle); } function statetoggle() { opened = !opened; } }); // 兼容方法 function geteventtarget(e) { try { if (e.target) geteventtarget = function (e) { return e.target; } else throw undefined; } catch (exp) { geteventtarget = function () { return window.event.srcelement; } } return geteventtarget(e); } function geteventtargettext(t) { if ("innertext" in t) geteventtargettext = function (t) { if (t.nodename === "p") return; return t.innertext; }; else geteventtargettext = function (t) { if (t.nodename === "p") return; return t.textcontent; }; return geteventtargettext(t); } })(); // 子栏目 hover (function() { var sup = $('#content .columns'); if (!sup.length) return; var links = sup.find('a'), on = links.filter('.on'), link = on; links.hover(function() { link.removeclass('on'); link = $(this).addclass('on'); }, function(){}); sup.hover(function(){}, function() { link.removeclass('on'); link = on.addclass('on'); }); }()); // tab 切换 (function() { var menu = $('#left .tabmenu'); if (!menu.length) return; var cont = $('#left .tabcont'), m_items = menu.children(), c_items = cont.children(), index = 0, prev_i = -1, curr_m = m_items.eq(index).addclass('on'), curr_c = c_items.eq(index).stop().slidedown(300); m_items.on('click', function(elem, idx) { elem = $(this); idx = elem.index(); if (idx === prev_i) return; prev_i = idx; curr_m.removeclass('on'); curr_m = m_items.eq(idx).addclass('on'); curr_c.stop().slideup(300); curr_c = c_items.eq(idx).stop().slidedown(300); }); }()); });