【问题标题】:Magnific popup html page scroll top problemMagnific popup html页面滚动顶部问题
【发布时间】:2020-05-11 23:57:28
【问题描述】:

我在我的网站上使用magnific popups。当我单击图像时,它会在弹出窗口中调用另一个(第二个)html 页面,并且效果很好。

我的问题是,当弹出窗口打开时,我想使用以下代码将第二页滚动到顶部:

window.scrollBy(0, 0);

但它不起作用。它将后面的内容滚动到顶部。

我想将第二个 html 页面滚动到弹出窗口内的顶部。

我该怎么做? 这是我在第二个 html 中的代码:

    $('.accordion a').click(function(j) {

          //window.scrollTo(0, 0);
          //document.getElementById(aa).onload = function(){ this.contentWindow.scrollBy(0,0);};
          //window.parent.scrollTo(0,0);
          //this.contentWindow.scrollTo(0,0);

            var dropDown = $(this).closest('li').find('p');

            $(this).closest('.accordion').find('p').not(dropDown).slideUp();

            if ($(this).hasClass('active')) {
                $(this).removeClass('active');
            } else {
                $(this).closest('.accordion').find('a.active').removeClass('active');
                $(this).addClass('active');
            }

            dropDown.stop(false, true).slideToggle();

            j.preventDefault();
        });

【问题讨论】:

    标签: javascript magnific-popup


    【解决方案1】:

    这将是管理主页内一些 iframe 的方式:

    document.getElementById("YourInsideItemID").onload = function () { this.contentWindow.scrollBy(0, 0); };

    【讨论】:

    • 它确实有效。我在另一个函数中使用了“this.contentwindow”部分代码,但它不起作用。
    • 注意:我想在第二个 html 文件中使用滚动代码。不在放大的弹出主文件中。
    • 你能把你的示例代码放到测试中吗?在这里或其他在线服务上更好地检查问题。
    • 将 scrollBy 代码放入 setTimeout 中,例如延迟一秒并对其进行测试。 setTimeout(_=>{你的代码}, 1000);
    • 这没用。所有滚动代码都会影响到主页。但我想滚动第二页。 socend 页面的类型为:ajax。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    相关资源
    最近更新 更多