首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹出式自动滚动体内容

弹出式自动滚动体内容
EN

Stack Overflow用户
提问于 2015-03-06 12:17:34
回答 2查看 4.1K关注 0票数 0

我在这个网站上安装了网站

每次我点击一个缩略图启动灯箱,背景中的身体内容会稍微向下滚动。有什么办法能阻止这种事发生吗?

我感觉到lightbox脚本在某种程度上干扰了我的滚动到顶部代码:

代码语言:javascript
复制
    // Magnific Popup open inline content
    $('.open-popup-link').magnificPopup({
        type:'inline',
        midClick: true
    });

    // Magnific Popup open iframe content
    $('.vimeolink').magnificPopup({
        type: 'iframe',
    });

    // Smooth scrolling - https://css-tricks.com/snippets/jquery/smooth-scrolling/
    $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var target = $(this.hash);
            target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
            if (target.length) {
                $('html,body').animate({
                    scrollTop: target.offset().top
                }, 1000);
                return false;
            }
        }
    });

    // Scroll to top - http://www.paulund.co.uk/how-to-create-an-animated-scroll-to-top-with-jquery
    $(window).scroll(function(){
        if ($(this).scrollTop() > 100) {
            $('.scrollToTop').fadeIn();
        } else {
            $('.scrollToTop').fadeOut();
        }
    });

    // Click event to scroll to top
    $('.scrollToTop').click(function(){
        $('html, body').animate({scrollTop : 0},800);
        return false;
    });
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-06 13:06:30

$('a[href*=#]:not([href=#]')与单击的图像相匹配,例如<a class="open-popup-link" href="#popup-183">。所以是的,当你点击一个图片,不仅弹出,而且页面滚动到哈希在网址,在这种情况下,a#projects

例如,可以通过添加类来区分锚点的<a>和图像的<a>

代码语言:javascript
复制
<a class="scroller" href="#whatever"></a>

<a class="open-popup-link" href="#popup-183">

现在用他们的类来瞄准他们:

代码语言:javascript
复制
$('a.scroller').click(function() { /* scrolling stuff */ }
票数 1
EN

Stack Overflow用户

发布于 2015-08-13 15:13:04

您也可以尝试使用羽光。这个插件不使用链接中的href属性来显示内容,所以您不会遇到这个问题。它也更容易使用,它们的文档也更好(IMO)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28898633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档