Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-git2.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div class="scrollable">
      <ul>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
          <li>A bunch of items to make the div scroll</li>
      </ul>
  </div>
  <ul>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
      <li>A bunch of text to make the body scroll</li>
  </ul>
</body>
</html>
 
body.noscroll {
    overflow: hidden;
}
.scrollable {
    max-height: 200px;
    overflow-y: scroll;
    border: 1px solid #ccc;
}
 
var $document = $(document),
    $body = $('body'),
    $scrolable = $('.scrollable');
$scrolable.on({
          'mouseenter': function () {
            // save scroll position
            //var scrollPosition = $document.scrollTop();
            // add hack class to prevent workspace scroll when scroll outside
            $body.addClass('noscroll');
            // restore scroll position
            //element.scrollTop(scrollPosition);
          },
          'mouseleave': function () {
            // save scroll position
            //var scrollPosition = element.scrollTop();
            // remove hack class to allow scroll
            $body.removeClass('noscroll');
            // restore scroll position
            //$document.scrollTop(scrollPosition);
          }
        });
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers