【问题标题】:scroll to iframe when using a target link使用目标链接时滚动到 iframe
【发布时间】:2018-12-06 15:48:45
【问题描述】:

我需要弄清楚如何组合目标链接和 iframe。我使用 iframe 托管视频并使用目标链接让观众更改 iframe 中正在播放的视频,有时我们有很多不同的问题,页面可能会很长,所以我需要弄清楚如何滚动到 iframe链接被点击。我试过结合锚标签,但我想不通。任何帮助表示赞赏!

<div class="c-sponsored-landing__main-video">
    <div class="embed-responsive embed-responsive-16by9">
        <iframe name="video" src="https://player.vimeo.com/video/274107021?rel=0&amp;autoplay=1&amp;showinfo=0"
            webkitallowfullscreen mozallowfullscreen allowfullscreen class="embed-responsive-item"></iframe>
    </div>
</div>

<div class="c-sponsored-landing__thumbnails">
    <div class="row">
        <div class="col-sm-3">
            <a href="https://player.vimeo.com/video/274107021?rel=0&autoplay=1&showinfo=0" target="video"><img src="https://www.visioncareprofessional.com/digital/notalvision/1/seg1.png"
                    class="img-thumbnail img-responsive center-block"></a>
            <p><strong class="green">Q1:</strong> Why is monitoring intermediate AMD important?</p>
        </div>
        <div class="col-sm-3">
            <a href="https://player.vimeo.com/video/274107111?rel=0&autoplay=1&showinfo=0" target="video"><img src="https://www.visioncareprofessional.com/digital/notalvision/1/seg2.png"
                    class="img-thumbnail img-responsive center-block"></a>
            <p><strong class="green">Q2:</strong> What impact does early Wet AMD detection have on visual outcomes?</p>
        </div>
        <div class="col-sm-3">
            <a href="https://player.vimeo.com/video/274107379?rel=0&autoplay=1&showinfo=0" target="video"><img src="https://www.visioncareprofessional.com/digital/notalvision/1/seg3.png"
                    class="img-thumbnail img-responsive center-block"></a>
            <p><strong class="green">Q3:</strong> If the goal is early Wet AMD detection to help prevent vision loss,
                then how are we doing?</p>
        </div>
        <div class="col-sm-3">
            <a href="https://player.vimeo.com/video/274133949?rel=0&autoplay=1&showinfo=0" target="video"><img src="https://www.visioncareprofessional.com/digital/notalvision/1/seg4.png"
                    class="img-thumbnail img-responsive center-block"></a>
            <p><strong class="green">Q4:</strong> What impact does severe vision loss have on a patient's quality of
                life? </p>
        </div>
    </div>
</div>

直播链接:https://www.visioncareprofessional.com/digital/notalvision/1/index3.html

【问题讨论】:

    标签: javascript html iframe target


    【解决方案1】:

    您可以获取视频的引用并在链接上监听点击事件,一旦触发点击事件,阻止正常行为并使用scrollIntoView显示视频。

    const video = document.getElementById("video")
    const links = document.querySelectorAll("a")
    
    links.forEach(link => {
        link.addEventListener("click", (e) => {
        e.preventDefault()
        // LOGIC TO CHANGE THE VIDEO
        video.scrollIntoView({ block: 'end',  behavior: 'smooth' });
      })
    })
    

    https://jsfiddle.net/dupftwqa/1/

    【讨论】:

    • 滚动正在工作,但现在 iframe 没有更新新视频。
    • 您必须添加逻辑来更改我放置评论的链接,我的代码只是如何进行滚动的示例。
    • 我在下面发布了一个新代码。我把逻辑放在哪里?我是不是把 url 链接放到下面的 java 里面了?
    • 您可以将逻辑放在 e.preventDefault() 之后的任何位置,您的想法是在我放置评论的位置添加逻辑 // LOGIC TO CHANGE THE VIDEO
    【解决方案2】:

    滚动正在工作,但现在 iframe 没有更新新视频。

        <div class="c-sponsored-landing__main-video" id="video">
            <div class="embed-responsive embed-responsive-16by9"><iframe allowfullscreen="" class="embed-responsive-item" mozallowfullscreen="" name="video" src="https://player.vimeo.com/video/303509941?rel=0&amp;autoplay=1&amp;showinfo=0" webkitallowfullscreen=""></iframe></div>
        </div>
    
        <div class="c-sponsored-landing__thumbnails">
            <div class="row">
                <div class="col-md-6">
                    <div class="row grey-box1">
                        <div class="col-sm-6">
                            <a href="https://player.vimeo.com/video/303509941?rel=0&amp;autoplay=1&amp;showinfo=0" target="video"><img class="img-responsive center-block" src="https://www.visioncareprofessional.com/digital/aerie/1/1-simmons.png" /></a>
                            <p class="text-center small"><strong>Steve Simmons, MD</strong></p>
                        </div>
    
                        <div class="col-sm-6">
                            <a href="https://player.vimeo.com/video/303547792?rel=0&amp;autoplay=1&amp;showinfo=0" target="video"><img class="img-responsive center-block" src="https://www.visioncareprofessional.com/digital/aerie/1/1-singh.png" /></a>
                            <p class="text-center small"><strong>Inder Paul Singh, MD</strong></p>
                        </div>
    
                        <h4>How does Rhopressa<sup>&reg;</sup> address some of the key considerations in the medical management of glaucoma?</h4>
                    </div>
                </div>
    
                <div class="col-md-6">
                    <div class="row grey-box3">
    
                        <div class="col-sm-6">
                            <a href="https://player.vimeo.com/video/303547723?rel=0&amp;autoplay=1&amp;showinfo=0" target="video"><img class="img-responsive center-block" src="https://www.visioncareprofessional.com/digital/aerie/1/1-singh.png" /></a>
                            <p class="text-center small"><strong>Inder Paul Singh, MD</strong></p>
                        </div>
    
                        <div class="col-sm-6">
                            <a href="https://player.vimeo.com/video/303349557?rel=0&amp;autoplay=1&amp;showinfo=0" target="video"><img class="img-responsive center-block" src="https://www.visioncareprofessional.com/digital/aerie/1/1-radcliffe.png" /></a>
                            <p class="text-center small"><strong>Nathan Radcliffe, MD</strong></p>
                        </div>
                        <h4>Why does the mechanism of action of Rhopressa<sup>&reg;</sup> make it a significant addition to the therapeutic armamentarium for glaucoma?</h4>
    
                    </div>
                </div>
            </div>
        </div>
    <script type="text/javascript">
    const video = document.getElementById("video")
    const links = document.querySelectorAll("a")
    
    links.forEach(link => {
        link.addEventListener("click", (e) => {
        e.preventDefault()
        // LOGIC TO CHANGE THE VIDEO
        video.scrollIntoView({block: 'nearest',  behavior: 'smooth' });
      })
    })
    </script>
    

    【讨论】:

      猜你喜欢
      • 2014-01-29
      • 2015-10-02
      • 2012-02-29
      • 1970-01-01
      • 2012-11-12
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多