admin管理员组文章数量:1426652
I have a simple .slideDown
function:
$globalTabs.find('.seeMore a').live("click", function(){
$globalTabs.find(".allTabs").slideDown('slow');
});
When a user clicks on an <a>
in .allTabs
,.allTabs
does a .slideUp
.
What I want to do, is if a user has not clicked anything in .allTabs
and the mouse is no longer within .allTabs
, then a timer initiates to wait x amount of time and then do the .slideUp
. Additionally, if the mouse enters .allTabs
again before the .slideUp
triggers - then the timer is stopped and resets when the mouse is moved outside of .allTabs
Not sure how to approach. Any help would be appreciated.
base markup:
<div class="allTabs">
<a href="#">link 1</a>
<a href="#">link 2</a>
<a href="#">link 3</a>
<a href="#">link 4</a>
</div>
and:
<li class="seeMore"><a href="#">see more</a></li>
I have a simple .slideDown
function:
$globalTabs.find('.seeMore a').live("click", function(){
$globalTabs.find(".allTabs").slideDown('slow');
});
When a user clicks on an <a>
in .allTabs
,.allTabs
does a .slideUp
.
What I want to do, is if a user has not clicked anything in .allTabs
and the mouse is no longer within .allTabs
, then a timer initiates to wait x amount of time and then do the .slideUp
. Additionally, if the mouse enters .allTabs
again before the .slideUp
triggers - then the timer is stopped and resets when the mouse is moved outside of .allTabs
Not sure how to approach. Any help would be appreciated.
base markup:
<div class="allTabs">
<a href="#">link 1</a>
<a href="#">link 2</a>
<a href="#">link 3</a>
<a href="#">link 4</a>
</div>
and:
<li class="seeMore"><a href="#">see more</a></li>
Share
Improve this question
edited Aug 25, 2012 at 1:17
d.k
4,4702 gold badges32 silver badges41 bronze badges
asked Aug 25, 2012 at 0:46
JasonJason
7,70015 gold badges79 silver badges129 bronze badges
2
-
@Jason, Should it be read as
.allTabs
does a.slideDown
, not a.slideUp
? – d.k Commented Aug 25, 2012 at 0:54 -
@caligula - it does a slidedown, and then when you click in
allTabs
it does a slideUp. I also just saw that our site is loading hoverIntent - which may make this easier – Jason Commented Aug 25, 2012 at 0:59
3 Answers
Reset to default 4You can use setTimeout
and clearTimeout
functions, note that live
method has been deprecated, you can use the on
method instead.
var timeout;
$(document).on({
mouseenter: function(){
clearTimeout(timeout)
},
mouseleave: function(){
var $this = $(this)
timeout = setTimeout(function(){
$this.slideUp('slow')
}, 500)
},
}, ".allTabs")
Fiddle
Update:
var timeout;
$(document).delegate(".allTabs", "mouseenter", function() {
clearTimeout(timeout)
})
$(document).delegate(".allTabs", "mouseleave", function() {
var $this = $(this)
timeout = setTimeout(function() {
$this.slideUp('slow')
}, 1000)
})
Fiddle
Set a timer to do the slideup
in the callback of the slidedown
and on mouseout
of .allTabs
. Cancel the timer on mouseover
on .allTabs
.
var $timer;
function hideAllTabs() {
$globalTabs.find(".allTabs").slideUp('slow');
}
$globalTabs.find('.seeMore a').live("click", function(){
$globalTabs.find(".allTabs").slideDown('slow', function() {
$timer = setTimeout(hideAllTabs, 1000);
});
});
$globalTabs.find(".allTabs").live("mouseout",function() {
$timer = setTimeout(hideAllTabs, 1000);
});
$globalTabs.find(".allTabs").live("mouseover",function() {
clearTimeout($timer);
});
Try this way:
$(function() {
var $allTabs = $globalTabs.find(".allTabs");
var timer;
$globalTabs.find('.seeMore a').live("click", function(){
$allTabs.slideDown('slow');
});
$allTabs.mouseout(function(){
timer = setTimeout(function() {$allTabs.slideUp()}, 3000);
});
$allTabs.mouseover(function() {
clearTimeout(timer);
});
});
本文标签: javascriptjQuery slideDown amp then slideUp on timerStack Overflow
版权声明:本文标题:javascript - jQuery slideDown & then slideUp on timer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745471265a2659760.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论