停止href#跳转到页首 [英] Stop an href # from jumping to top of page

查看:147
本文介绍了停止href#跳转到页首的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有手风琴,但是当我点击其中一个标签页时,页面跳到手风琴的顶部。目前没有jquery控制动画它是所有的CSS。是否有办法阻止此情况?

I have an accordion on my page, but when I click one of the tabs the page jumps to the top of the accordion. At the moment there is no jquery controlling the animation it's all CSS. Is there a way to stop this?

          <section id="contact">

            <h2><a href="#contact">Contact</a></h2>

            <p>Lorem ipsum dolor sit amet </p>

          </section>


推荐答案

尝试防止默认行为, event.preventDefault()

<h2><a href="#contact" class="PartOfAccordion">Contact</a></h2>

<script type="text/javascript">
  $('.PartOfAccordion').click( function(e) {
   e.preventDefault();
  });
</script>

这篇关于停止href#跳转到页首的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆