Javascript 如何删除某些效果(悬停流)?
我正在使用一个JQuery插件,到目前为止,它的工作与我预期的一样,但是当屏幕大小调整到799px以下时,我想将其删除,当屏幕大小调整到800px以上时,我想重新添加它。这是我的代码:Javascript 如何删除某些效果(悬停流)?,javascript,jquery-plugins,Javascript,Jquery Plugins,我正在使用一个JQuery插件,到目前为止,它的工作与我预期的一样,但是当屏幕大小调整到799px以下时,我想将其删除,当屏幕大小调整到800px以上时,我想重新添加它。这是我的代码: function setEffects() { if(document.documentElement.clientWidth >= 800){ if($("#menu-main-nav-menu a span").length == 0){ $("#menu
function setEffects() {
if(document.documentElement.clientWidth >= 800){
if($("#menu-main-nav-menu a span").length == 0){
$("#menu-main-nav-menu a").append("<span> </span>");
$("#menu-main-nav-menu a").hover(function(e) {
$(this).hoverFlow(e.type, { width: 248 }, 200)
.css('overflow', 'visible')
.find('span')
.hoverFlow(e.type, { width: 5 }, 200)
}, function(e) {
$(this).hoverFlow(e.type, { width: 233 }, 200)
.css('overflow', 'visible')
.find('span')
.hoverFlow(e.type, { width: 20 }, 200)
});
}
}else{
if($("#menu-main-nav-menu a span").length != 0){
$("#menu-main-nav-menu a").remove('span');
}
}
}
$(document).ready(setEffects);
window.onresize = setEffects;
函数setEffects(){
如果(document.documentElement.clientWidth>=800){
if($(“#菜单主导航菜单a跨距”)。长度==0){
$(“#菜单主导航菜单a”)。追加(“ ”);
$(“#菜单主导航菜单a”)。悬停(功能(e){
$(this).hoverFlow(e.type,{width:248},200)
.css('溢出','可见')
.find('span'))
.hoverFlow(e.type,{width:5},200)
},功能(e){
$(this).hoverFlow(e.type,{width:233},200)
.css('溢出','可见')
.find('span'))
.hoverFlow(e.type,{width:20},200)
});
}
}否则{
如果($(“#菜单主导航菜单a跨距”).length!=0{
$(“#菜单主导航菜单a”)。删除('span');
}
}
}
$(文档).ready(setEffects);
window.onresize=setEffects;
提前感谢,如果您有问题,请告诉我:-)尝试解除活动绑定:
$(this).unbind(e.type);
谢谢你的回答!但是没有起作用。我试过这个$(“#menu main nav menu a”).hover(函数(e){$(this.unbind(e.type);});在“else”语句之后,看起来您只需更改
$(“#菜单主导航菜单a”)。删除('span')
到$(#menu main nav menu a”).unbind(e.type)
。您的原始代码有效吗?您的html是什么?我有一个类似的问题:我无法使效果在JSF上有效