2016-05-17 5 views
-1

私は現在、2つのdivsを並べています。ページの読み込み時に、左側のdivはウィンドウの高さの100%を占める必要があり、垂直方向の中央のコンテンツを持つ必要があります。右のdivの内容は長くなり、スクロールが必要になります。右のdivが完全にスクロールされたら、両方のdivの下のコンテンツを表示するように本文をスクロールしてください。本文をスクロールする前にdivの強制スクロール

カーソルが右のdivにあるときはうまく動作しますが、左のdivの上にあるときは、右のdivの内容ではなく本文がスクロールします。ボディスクロールの前に右のdivのスクロールを強制するためにCSSを使うことはできますか?これはjsの仕事ですか?

**もう一度スクロールして右のdivにスクロールしてしまうと、醜い状況が発生することがわかりました。 GROAN。私は実際に必要なのは、左のdivをスクロールに貼り付け、コンテナの最後に放すことだと思っています。これに最適なソリューションは何ですか? **

私が望むように動作するjQuery Stickemを使用して、スティッキdivを見始めましたが、もっと簡単に確実に達成できることはおそらく残念です。私は解決策は、すべてのアドバイス歓迎IE8 +

.top-content {position:relative; height:100vh} 
 

 
.left-div {background-color:blue; float:left; width:35%; height:100%;} 
 

 
.right-div {background-color:yellow; float:right; width:65%; height:100%; overflow:scroll;} 
 

 
.bottom-contet {position:relative; background-color:pink; height:500px;}
<div class="top-content"> 
 
\t <div class="left-div">Currently, if the cursor is over the right div the page works as required. But if over this left div then the body scrolls straight to content below. I want it to always scoll the right div regardless of cursor position</div> \t 
 
    <div class="right-div"> 
 
    \t <p>scrolling right stuff</p> 
 

 
    \t <p>scrolling right stuff</p> 
 

 
    \t <p>scrolling right stuff</p> 
 

 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 

 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 

 
    \t <p>scrolling right stuff</p> 
 

 
    \t <p>scrolling right stuff</p> 
 

 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 
     
 
    \t <p>scrolling right stuff</p> 
 

 
    \t <p>scrolling right stuff</p>  
 
\t </div>  
 
</div> 
 
     
 
<div class="bottom-contet"> 
 

 
    \t \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
    \t <p>content below</p> 
 
     
 
</div>

を含むすべてのブラウザで動作しなければならない必要が

は、私が欲しい、非常にどのようなフィット同様の質問が、どれを発見しました。

答えて

0

右側のdivのスクロールイベントを聞くことが1つの解決策です。最大スクロール値とともにelement.scrollTopを使用してスクロール(またはクローズ)しているかどうかを確認できます。最初は、本体のoverflow-yhiddenに設定することができます。内側divのスクロール位置に達したら、overflow-y: scrollに変更することができます。この変更はjs/jqueryで行うことができます。

また、逆のシナリオを処理する必要があります。ユーザーは初期状態に戻ることができます。

0

スクロールをトップコンテンツdivに適用し、左側のdivを修正してみます。 それは仕事をする必要があります。 後でいくつかの余白を調整する必要があるでしょう。

はこれにあなたのCSSを変更し

.top-content {position:relative; height:100%; overflow: scroll} 

.left-div {background-color:blue; float:left; width:35%; height:100%; position: fixed} 

.right-div {background-color:yellow; float:right; width:65%; height:100%; } 

.bottom-contet {position:relative; background-color:pink; height:500px;} 
+0

この上のご回答ありがとうございました。私はそれを正しく説明していなかったと思いますが、スティック部門は実際に学校が終了したときに「バンプ」効果を得るために必要なものでした。私は役に立つsticky divの例を見つけましたが、幅の問題で苦労しているので、新しい質問が投稿されました。可能であれば、これを試して削除します。 –

0

あなたはこのような何かを行うことができます:

最初に変数を作成し、右側のウィンドウがスクロールされていないことを示すためにfalseにその値を設定しましたダウン。ページをスクロールすると、その変数がまだfalseであれば、ウィンドウが上部に留まるように強制することができます。右ウィンドウが一番下にスクロールされると、その変数の値をtrueに変更することができます。これにより、先頭に戻ってくるスクリプトが停止し、下のコンテンツにアクセスすることができます。 WF4 @

//unable to scroll down by default 
 
var rightScrolled = false; 
 
//when we scroll the page... 
 
$(window).on('scroll', function(){ 
 
    //check if we have scrolled the right window to the bottom 
 
\t if(rightScrolled == false) { 
 
     //we haven't, force the window to remain at the top 
 
    \t  window.scrollTo(0, 0); 
 
    } 
 

 
}); 
 

 
$(function($) { 
 
    //when we scroll the right div... 
 
    $('.right-div').on('scroll', function() { 
 
     //check if we have reached the bottom 
 
     if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) { 
 
      //if we have, set our variable to true 
 
      rightScrolled = true; 
 
     } 
 
    }) 
 
});
.top-content {position:relative; height:100vh} 
 

 
    .left-div {background-color:blue; float:left; width:35%; height:100%;} 
 

 
    .right-div {background-color:yellow; float:right; width:65%; height:100%; overflow:scroll;} 
 

 
    .bottom-contet {position:relative; background-color:pink; height:500px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    <div class="top-content"> 
 
    \t <div class="left-div">Currently, if the cursor is over the right div the page works as required. But if over this left div then the body scrolls straight to content below. I want it to always scoll the right div regardless of cursor position</div> \t 
 
     <div class="right-div"> 
 
     \t <p>scrolling right stuff</p> 
 

 
     \t <p>scrolling right stuff</p> 
 

 
     \t <p>scrolling right stuff</p> 
 

 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 

 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 

 
     \t <p>scrolling right stuff</p> 
 

 
     \t <p>scrolling right stuff</p> 
 

 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 
      
 
     \t <p>scrolling right stuff</p> 
 

 
     \t <p>scrolling right stuff</p>  
 
    \t </div>  
 
    </div> 
 
      
 
    <div class="bottom-contet"> 
 

 
     \t \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
     \t <p>content below</p> 
 
      
 
    </div>

関連する問題