2017-11-15 10 views
0

長いテキストのライトボックスがあり、アンカーリンクを使用してライトボックスを開くことができます。この方法で別のセクションに移動しますテキストの長いテキストのライトボックスを開き、テキストのセクションへのアンカーリンク

誰かが助けてくれることを願っています!

<a href="#section1">Link1</a> 
<a href="#section2">Link1</a> 

<div class="lightbox"> 
<div id="section1"> 
Hello world 
</div> 
<br> 
<br> 
<br> 
<br> 
<br> 
<br> 
<br> 
<br> 
<br> 
<br> 
<div id="section2"> 
Hello again world 
</div> 
</div> 
+0

あなたは「別のセクションに進んでください」とはどういう意味ですか?指定した選択肢のみを表示するか、アンカーにスクロールしますか? – Janis

答えて

0

のような:)

何かあなたがアンカーにスクロールしたい場合は、私はそうのように、fancyBox3を使用することをお勧め:

1リンクを作成します。

<a href="#test" data-fancybox data-anchor="#section1">Link1</a> 
<a href="#test" data-fancybox data-anchor="#section2">Link2</a> 

2インラインコンテンツを作成する:

<div id="test" style="display:none;width:300px;"> 
    <div id="section1"> 
    Hello world 
    </div> 
    <div style="height: 500px;background: #ccc;"></div> 
    <div id="section2"> 
    Hello again world 
    </div> 
</div> 

3を使用するコールバックアンカーを見つけ、トップの位置にスクロールする:

$('[data-fancybox]').fancybox({ 
    afterShow: function(instance, current) { 
    var top = $(current.opts.$orig.data('anchor')).position().top - 24; 

    current.$slide.animate({ scrollTop: top }, 200); 
    } 
}); 

デモ - https://codepen.io/anon/pen/LOzEOj?editors=1010

関連する問題