开发者

How to make <div> .slideUp work with .delay() elsewhere

Sorry for the bad title, not easy to explain in such a short area.

What I'm trying to accomplish: I've got a little notifications bar that slides down from the top of my site when you go to a link when you're not signed in. It just says 'you can't go here' in a clever way. Once you click it, it slides down, then using .delay(), it waits 2500ms and then slides back up. I'd like it so if you click a new one, it will cancel the delay and immediately slide up the old one and bring down a new one.

The problem is: If you click the button to bring down the notification over and over, it will wait for the .delay to finish before going to the next one, thus creating and endless stream of notifications that you'd have to wait through. I'd like it so when you click a new tab, it stops the .delay and immediately goes there, so you don't have the delay if you're compulsive or accidentally click.

My website: http://thenozzle.net/

The notification comes down when you click the 'games', 'projects', 'contests' or 'forums' links in the menubar.

Javascript:

function notifyevent(){
    $('#subscribercontent').slideUp('fast');
    $('#subscribercontent').slideDown('fast').delay(2500).slideUp('fast')
}

Make sense? I see this problem all over the place, where if you click multiple times, it must wait for the delay to finish. But I don't want to get rid of the slide up and slide back down, because I want that action-re开发者_如何学JAVAaction fell of the notification, so you can associate the notification bar being down with your clicking.

Thanks!


I solved it, actually thanks to a combination of answers.

function notifyevent(){
    $('#searchoverflow').slideUp('fast');
    $('#subscribercontent').slideUp('fast');
    $('#subscribercontent').slideDown('fast');
    setTimeout("$('#subscribercontent').stop(true,true).slideUp('fast');", 3000)
}

I use the setTimeout instead of delay, then I use .stop() not to stop a delay, but to stop the animation before the timeout. If anyone knows of a better way, that'd be great, with way kinda destroys the timer if you clickspam, and people will do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜