平滑滚动链接与/ fancybox冲突,将href改为class或id

Smooth Scrolling links conflicting w/ fancybox, change href to class or id?

本文关键字:href 改为 class id 冲突 链接 滚动 fancybox 平滑      更新时间:2023-09-26

我用这个来做上下滚动的过渡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 id '在适当的地方,并创建一个共享类(例如.smooth和调用在两个链接),但它刚刚破裂。我如何使用这只指定两个div为它适用?

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

修改如下:

$('#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;
    });
});

当点击'Gallery'并打开fancybox时,滚动是没有意义的。