我正在使用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>
我不知道你是否需要再看一下,但是下拉菜单只是一个列表,但是我希望能够将它应用到静态图像中,直到下拉菜单出现。< / p>
答案 0 :(得分:1)
dropshadow插件似乎是为固定页面元素设计的。来自dropshadow的js文件:
“这个jQuery插件在页面元素后面添加了柔和的阴影。它仅用于为大多数固定对象添加一些阴影,如页面标题,照片或内容容器”
编辑:也许你可以用css实现你正在寻找的效果? http://robertnyman.com/2010/03/16/drop-shadow-with-css-for-all-web-browsers/答案 1 :(得分:0)
问题在于CSS,当第一次调用dropShadow()时,类dropShadow的css被设置为hiddent(这是放在那里使动态部分在IE中运行(所有其他浏览器没有它)。在javascript中你可以通过$('。dropShadow')来看到这个.css('visibility','visible');被调用。