【问题标题】:Smooth Scrolling links conflicting w/ fancybox, change href to class or id?平滑滚动链接与花式框冲突,将 href 更改为 class 或 id?
【发布时间】:2011-12-18 04:25:57
【问题描述】:

我正在使用它在顶部和底部 div 之间进行滚动转换:

<script type="text/javascript">

$('a').on('click', function (event) {
    event.preventDefault();//stop the browser from jumping to the anchor
    var href  = $(this).attr('href'),
        oset  = $(href).offset().top;
    $('html, body').stop().animate({
        scrollTop : oset
    }, 1000, function () {
        location.hash = href;
    });
});

</script>

但这与我使用fancybox的方式相冲突,因为它使用'href',我尝试定义'div ids'并创建一个共享类(例如.smooth并在两个链接中调用)但它只是坏了。我怎样才能使用这个指定只有两个 div 来应用它?

问题来自 - https://stackoverflow.com/questions/8547378/fancybox-with-iframe-js-conflictions-with-my-site-wont-implement

【问题讨论】:

  • 它的 HTML 是什么?为什么点击此链接会触发fancybox?
  • 这是我一直在开发的地方,“tinyurl.com/7dqupdm”点击“图库”,它就死了。当我删除上面的代码时,该链接的幻想框可以完美运行吗?

标签: javascript jquery html css


【解决方案1】:

改变这个:

$('#menu a').on('click', function (event) {
    event.preventDefault();//stop the browser from jumping to the anchor
    var href  = $(this).attr('href'),
        oset  = $(href).offset().top;
    $('html, body').stop().animate({
        scrollTop : oset
    }, 1000, function () {
        location.hash = href;
    });
});

点击“画廊”打开fancybox时滚动没有意义。

【讨论】:

  • 感谢理查德 - 这对菜单很有效。但我需要合并#bottom 和#top div(从页面左侧)。我怎么能调用多个 div; (#menu, #bottom, #top a)?
  • 是的,完美:-) 简单地选择“a”有点“贪婪”。当您不希望触发该函数时,您可以考虑添加一个类: $('a').not('.noScroll').on('click', function (event) {
  • Ehm,在你的代码中你犯了一个小错误,应该是:(“#menu a, #bottom a, #top a”)。你错过了a的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-30
  • 2013-04-12
  • 1970-01-01
相关资源
最近更新 更多