joj*_*ojo 7 jquery triggers slider
我用jquery创建一个小滑块插件.当鼠标位于左侧或右侧控制区域上方时,图像将从左侧或右侧滑动5%.点击图片滑入100%
问题是当在完全幻灯片中从左到右控制div时移动鼠标时,请检查鼠标是否总是在左侧div上再次触发鼠标悬停事件.结果是左侧和右侧的图像显示为5%.
有没有办法像这样检查鼠标悬停?
if($(this).mouseover())
$(".right").trigger("mouseover");
Run Code Online (Sandbox Code Playgroud)
控制器div的代码看起来像这样
$(".right",this).bind({
mouseover:function(){
if( vars.current == $("img").length-1 || vars.running) return false;
$("img:eq("+(vars.current+1)+")").removeAttr("style").css({position:"absolute",left:"100%","z-index":vars.current+1}).show().animate({left:"95%"}, {queue: false})
},
mouseleave:function(){
if( vars.current == $("img").length-1 || vars.running) return false;
$("img:eq("+(vars.current+1)+")").animate({left:"100%"}, {queue: false , complete:function(){ $(this).hide() } });
},
click:function(){
if( vars.current == $("img").length-1 || vars.running) return false;
vars.running = true;
$("img:eq("+(vars.current+1)+")").animate({left:"0%"}, {queue: false, complete:function(){
$("img:eq("+vars.current+")").hide();
$(this).css({"z-index":0})
vars.current++;
vars.running = false;
if($(this).mouseover())
$(".right").trigger("mouseover");
} } );
}
})
Run Code Online (Sandbox Code Playgroud)
我用其他答案的方式......但它的删除....
mouseover:function(){
isOver = 'right';
if( vars.current == $("img").length-1 || vars.running) return false;
$("img:eq("+(vars.current+1)+")").removeAttr("style").css({position:"absolute",left:"100%","z-index":vars.current+1}).show().animate({left:"95%"}, {queue: false})
},
mouseleave:function(){
isOver = false
if( vars.current == $("img").length-1 || vars.running) return false;
$("img:eq("+(vars.current+1)+")").animate({left:"100%"}, {queue: false , complete:function(){ $(this).hide() } });
},
click:function(){
if( vars.current == $("img").length-1 || vars.running) return false;
vars.running = true;
$("img:eq("+(vars.current+1)+")").animate({left:"0%"}, {queue: false, complete:function(){
$("img:eq("+vars.current+")").hide();
$(this).css({"z-index":0})
vars.current++;
vars.running = false;
if(isOver)
$("."+isOver).trigger("mouseover");
} } );
}
Run Code Online (Sandbox Code Playgroud)
通过使用var isOver我可以触发向左或向右
act*_*imp 32
要检查是否有东西悬停,您可以使用:hover选择器,例如:
$('#test').click(function() {
if ($('#hello').is(':hover')) {
alert('hello');
}
});
Run Code Online (Sandbox Code Playgroud)
示例:http://jsfiddle.net/AyAZx/5/
mat*_*uds 20
actionshrimp的答案在jQuery 1.9.1中被破坏了.
请改用
$("#idOfYourElement:hover").length > 0
Run Code Online (Sandbox Code Playgroud)
在你的if条件下
http://jsfiddle.net/mathheadinclouds/ZKGqe/
| 归档时间: |
|
| 查看次数: |
24823 次 |
| 最近记录: |