JQuery就绪函数问题
JQuery ready function problems
我正在使用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');被呼叫。
相关文章:
- IE9的HTML5 Canvas getImageData()函数存在问题
- javascript中的特定函数出现问题
- 运行Infinite Scroll后调用函数时出现问题
- jQuery使用ajax自动完成问题-TypeError:this.source不是函数
- 将代码放入click函数时出现javascript问题
- 使用setInterval调用原型函数时出现问题
- 在HTML中调用函数时出现问题
- 异步中的回调函数出现问题'张贴'
- Jquery函数返回订单问题
- 带有 JavaScript 随机数函数的未知问题
- 关于函数的Javascript问题 - IIFE
- 作用域问题-此函数是否形成闭包-JavaScript
- 用于异步函数中的循环和定时问题
- Createjs冲突问题localToLocal不是函数错误
- 使用Breeze脱机数据时出现未定义的问题不是函数
- 尝试将变量传递到对象中时的作用域问题'的方法构造函数
- Javascript函数变量传递语法问题
- 函数范围问题-函数未定义
- Javascript作用域问题:函数在$(doc).ready()中可用,但在事件处理程序中不可用
- 实现“喜欢”功能的问题.函数只工作一次