JQuery就绪函数问题

JQuery ready function problems

本文关键字:问题 函数 就绪 JQuery      更新时间:2023-09-26

我正在使用dropShadow插件,JQuery ready函数有问题。

当我有这样的代码:

$(document).ready(function() {
    $('div#shadow').dropShadow();
    $('#navigation li.mainmenu').bind('mouseover', navigation_open);
    $('#navigation li').bind('mouseout', navigation_timer);
});

只有当下拉菜单出来时,它才会产生阴影,这是第二个功能。有什么想法吗?

JS的完整代码是:

$(document).ready(
function()
{
   $('#navigation li.mainmenu').bind('mouseover', navigation_open);
   $('#navigation li').bind('mouseout',  navigation_timer);
  });
 var timeout    = 500;
 var closetimer = 0;
 var ddmenuitem = 0;
 var highlightmenu = 0;
 var returncolor = 0;
 var textreturncolor = 0;
 var height = 0;
 var originaltop = 0;
 var resettop = 0;
 var top = 0;
 var shadowExists = 0;
 var dropshadow = 0;
function drawShadow(){
 //draw the shadow only on mouse enter
 dropshadow = $(this).find('ul').dropShadow({top: 4, opacity: 1});
 $('.dropShadow').css('visibility','visible');
 }
 function navigation_open()
 {  navigation_canceltimer();
    navigation_close();
     height = $(this).height();
ddmenuitem = $(this).find('ul');
//Double Liners are above 40 pixels
menu = ddmenuitem.find('li');
/*===Need to get the top pos. of the item and adjust it since it is absolute;      relative does not work*/
top = ddmenuitem.position().top;
resettop = top;
   if (height > 40){
    top = top - 53;
    }
    else{
    top = top - 35;
    }
ddmenuitem.css('top', top.toString() + "px");
//---ADD A DROP SHADOW...USING JQUERY PLUGIN
ddmenuitem.dropShadow({top: 4, opacity: 1});
$('.dropShadow').css('visibility','visible');
ddmenuitem.css('visibility', 'visible');
returncolor = $(this).find('a#highlight').css('background-color');
textreturncolor = $(this).find('a#highlight').css('color');
highlightmenu = $(this).find('a#highlight').css('background-color','#6487ad');
highlightmenu.css('color','#ffffff');
highlightmenu.css('font-weight','bold');}
 function navigation_close()
 {  if(ddmenuitem){
ddmenuitem.css('visibility', 'hidden');
ddmenuitem.css('top',resettop);
ddmenuitem.removeShadow();
}
if(highlightmenu){ highlightmenu.css('background-color',returncolor);
                    highlightmenu.css('color',textreturncolor);
                    }
 }
 function navigation_timer()
 {
  closetimer = window.setTimeout(navigation_close, timeout);}
 function navigation_canceltimer()
 {  if(closetimer)
    {
    window.clearTimeout(closetimer);
       closetimer = null;}}
 document.onclick = navigation_close;

静态的HTML是这样的:

<div id="shadow">
//images here
</div>

我不知道你是否还需要看,但是下拉菜单只是一个列表,但我希望能够将其应用于静态图像,直到下拉菜单出来。

dropshadow插件似乎是为固定页面元素设计的。从dropshadow js文件:

"这个jQuery插件在页面元素后面添加了柔和的阴影。它只用于在大多数静止的对象上添加一些阴影,比如页面标题、照片或内容容器。"

编辑:也许你可以用css来达到你想要的效果?http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/

问题出在CSS中,当第一次调用dropShadow()时,类dropShadow的CSS被设置为hiddent(这是为了让动态部分在IE中工作(没有它,所有其他浏览器都可以)。在javascript中,您可以通过$('.dropShadow').css('visibility','visible');被呼叫。