简体   繁体   English

jQuery滑动div消失

[英]Jquery sliding div disappearing

I'm doing a jquery site and I have a slide in and out div that I'm using to show share buttons. 我正在做一个jquery网站,并且有一张div进出幻灯片,用来显示共享按钮。 I'm using the same code on multiple pages. 我在多个页面上使用相同的代码。 On my first page it works great with no problems but every other page the div will slide out but slide right back in. It doesn't stop. 在我的第一页上,它工作正常,没有任何问题,但div的所有其他页面都会滑出,但向后滑回去。 Very confused. 很迷茫。

Here I have a fiddle and in the fiddle it works great! 在这里,我有一个小提琴,在小提琴中效果很好! But when I use the same code on other pages it's not working correctly. 但是,当我在其他页面上使用相同的代码时,它将无法正常工作。 http://jsfiddle.net/4hUzH/ http://jsfiddle.net/4hUzH/

<script>
$(function() {
    $('.toggleNotes').click(function() {        
$nextArticle = $(this).next('.article');        
$nextArticle.is(':visible') ? $nextArticle.slideUp() : $nextArticle.slideDown();         
return false;    
});
});
</script>

<style>
.article {
    display: none;
}
</style>

<a href="#" class="toggleNotes">Click here</a>

<div class="article">
    This is where the buttons show up.
</div>

Can anyone explain why it slides out and right back in? 谁能解释为什么它会滑出来然后又回到里面?

Turns out in my top.php I was also calling the same function. 原来在我的top.php中,我还调用了相同的函数。 So it was calling the instance twice. 因此它两次调用实例。 It only needs to be called once. 它只需要被调用一次。 Silly mistake. 愚蠢的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM