简体   繁体   English

缩短JavaScript

[英]Shorten JavaScript

I got some help a few weeks ago on some code for a drop down menu but I am wondering if it is possible to make the code shorter because the current code shown below is quite big, any help would be great. 几周前,我在下拉菜单的某些代码上获得了一些帮助,但我想知道是否有可能使代码更短,因为下面显示的当前代码很大,任何帮助都很好。

    $(document).ready(function(){
$("#zone-bar li em").mouseenter(function() {
   var hidden = $(this).parents("li").children("ul").is(":hidden");

   $("#zone-bar>ul>li>ul").hide()        
   $("#zone-bar>ul>li>a").removeClass();

   if (hidden) {
       $(this).parents("li").children("ul").toggle()
              .parents("li").children("a").addClass("zoneCur");
   } 
});

$("#zone-bar>ul>li>ul").mouseleave(function() {
   var hidden = $(this).parents("li").children("ul").is(":hidden");

   $("#zone-bar>ul>li>ul").hide()        
   $("#zone-bar>ul>li>a").removeClass();

   if (visable) {
       $(this).parents("li").children("ul").toggle()
              .parents("li").children("a").addClass("zoneCur");
   } 
});
        });

From the looks of it, this can be done using only CSS. 从外观上看,这只能使用CSS来完成。 Check out github The menus "switch branch" and "switch tags" are done using CSS only. 查阅github菜单“ switch branch”和“ switch tags”仅使用CSS完成。 Another option would be using a JS minifier 另一种选择是使用JS缩小器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM