2011-04-26 49 views
1

我已经写了这个功能是一个水平手风琴,到目前为止它运行良好,我已经将它添加到外部js文件中,并将其加载到每个页面中,我想要什么现在在主页上,删除悬停功能,并将颜色设置为#CCC。我用尽了一切,解开了一个,宽度相同再添悬停....取消某个页面上的功能

http://uwptestsite.uwpistol.net/menu.html

这里是测试页面。

我写的代码就在这里。

// JavaScript Document  

$(document).ready(function(){ 
    $(".letter-b").width(12); 
    $(".letter-b").css({"overflow":"hidden", "position":"relative"});  

$(".letter-b a").hover(
    function() { 
     $(this).parent().stop().animate({"width": "52"}, 300); 
    }, 
    function() { 
     $(this).parent().stop().animate({"width": "12"}, 300); 
    }); 

    $(".letter-e").width(12); 
    $(".letter-e").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-e a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "83"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "12"}, 300); 
     });  

    $(".letter-h").width(12); 
    $(".letter-h").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-h a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "53"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "12"}, 300); 
     }); 

    $(".letter-l").width(11); 
    $(".letter-l").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-l a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "54"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "11"}, 300); 
     }); 

    $(".letter-n").width(12); 
    $(".letter-n").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-n a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "43"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "12"}, 300); 
     });   

    $(".letter-o").width(12); 
    $(".letter-o").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-o a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "94"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "12"}, 300); 
     });  

    $(".letter-r").width(12); 
    $(".letter-r").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-r a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "95"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "12"}, 300); 
     }); 


    $(".letter-w").width(17); 
    $(".letter-w").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-w a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "95"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "17"}, 300); 
     }); 


    $(".letter-x").width(12); 
    $(".letter-x").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-x a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "52"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "12"}, 300); 
     }); 

    $(".letter-y").width(12); 
    $(".letter-y").css({"overflow":"hidden", "position":"relative"}); 

    $(".letter-y a").hover(
     function() { 
     $(this).parent().stop().animate({"width": "52"}, 300); 
     }, 
     function() { 
     $(this).parent().stop().animate({"width": "12"}, 300); 
     });  
}); 

我真的为此而努力,我想我需要禁用的选项,但是这将是使其成为该林不知道如何做一个插件..我不想每个页面启用链接项的列表,因为它的增长速度在一分钟,所以如果我可以这样做

$("letter-h").disableAccordion(); 

我希望我做的意义,我知道有人能有一个解决方案,感谢这个!

+1

我在这里完全错过了点,但如果你不希望在特定页面上悬停功能,只是不包括.'js'文件包含'.hover()'func灰。 – andyb 2011-04-26 09:03:20

回答

2

在你不希望使用该插件的页面(如果你对动态加载根据页面上的插件)你可以把:

<script type="text/javascript"> 
$(document).ready(function() 
{ 
    $(".letter-a").unbind("mouseenter mouseleave"); 
}); 
</script> 

,来电后包括JS文件

+0

解除绑定(“悬停”)将不起作用。 http://stackoverflow.com/questions/2727570/jquery-unbindhover-does-not-work – YNhat 2011-04-26 09:16:25

+0

编辑,欢呼声。 – Dormouse 2011-04-26 09:22:34

+0

它的工作原理!太多了! – 2011-04-29 07:08:29

1

您可以使用此代码:

$("letter-h").unbind('mouseenter mouseleave');