admin管理员组文章数量:1315333
I have a simple javascript/jQuery related question:
I have the following markup in my tumblr blog:
<a href="/page/#" class="pagination">NEXT</a>
The # above changes according to which page the user is on. ie: # is variable, and cannot be static.
With jQuery, I would like to perform an effect (slideUp();
, to be specific) before the new link is opened.
Is that possible?
I have tried both .click()
and .mousedown()
. Doesn't seem to work, since when I click the link, the new page opens up before any effects take place.
I have heard of preventDefault()
, but I'd like to shy away from that, for that would mean I must create a separate function to detect the page #, etc. (too much work~)
I have a simple javascript/jQuery related question:
I have the following markup in my tumblr blog:
<a href="/page/#" class="pagination">NEXT</a>
The # above changes according to which page the user is on. ie: # is variable, and cannot be static.
With jQuery, I would like to perform an effect (slideUp();
, to be specific) before the new link is opened.
Is that possible?
I have tried both .click()
and .mousedown()
. Doesn't seem to work, since when I click the link, the new page opens up before any effects take place.
I have heard of preventDefault()
, but I'd like to shy away from that, for that would mean I must create a separate function to detect the page #, etc. (too much work~)
2 Answers
Reset to default 8I remend against doing that. Just let the user change pages.
However, if you really want to, what you need to do is indeed preventDefault
(explicitly, or by returning false
from your handler), do the slideUp
, and then in the slideUp
pletion function, trigger the change in URL.
Like this:
$("a.pagination").click(function() {
// Grab the link's href
var href = this.href;
// Slide up the content you want to slide up
$("some_selector_here").slideUp(function() {
// Slide is finished, navigate
location.href = href;
});
// Prevent the default action of the link
return false;
});
You just need to defer changing of page's url:
$('.pagination').click(function(){
var link = this;
$('.some-other-element').slideUp(500, function(){
location.href = this.getAttribute('href');
});
return false;
});
本文标签: javascriptPerform a jQuery event before opening up a linkStack Overflow
版权声明:本文标题:javascript - Perform a jQuery event before opening up a link - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741976877a2408175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论