[Solved] How to make scroll menu? [closed]


You hadn’t imported jQuery library. In online tesing environments, like JSFiddle and CodePen, adding <script src="https://stackoverflow.com/questions/31142083/sth.js"></script> won’t work as they have separated HTML, JS and CSS into separate “consoles”. You have to use the menu to import external libraries.

https://blog.codepen.io/documentation/editor/adding-external-resources/

Your edited CodePen

// Create a clone of the menu, right next to original.
$('.menu').addClass('original').clone().insertAfter('.menu').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide();

scrollIntervalID = setInterval(stickIt, 10);


function stickIt() {

  var orgElementPos = $('.original').offset();
  orgElementTop = orgElementPos.top;               

  if ($(window).scrollTop() >= (orgElementTop)) {
// scrolled past the original position; now only show the cloned, sticky element.

// Cloned element should always have same left position and width as original element.     
orgElement = $('.original');
coordsOrgElement = orgElement.offset();
leftOrgElement = coordsOrgElement.left;  
widthOrgElement = orgElement.css('width');
$('.cloned').css('left',leftOrgElement+'px').css('top',0).css('width',widthOrgElement).show();
$('.original').css('visibility','hidden');
  } else {
// not scrolled past the menu; only show the original menu.
$('.cloned').hide();
$('.original').css('visibility','visible');
  }
}
*{
   margin: 0;
   padding: 0;
}
.menu {
  width: 100%;
  float: left;
  margin-left: 0px;
  text-align: left;
  background-color: #2f4a67;
  margin-bottom: 0px;
  height: 50px;
}
.menu ul {
  margin-top: 0px;
}
.menu ul a li {
  display: inline-block;
  margin-right: 4%;
  padding-right: 1%;
  padding-top: 0.6%;
  padding-bottom: 0.6%;
  padding-left: 1%;
  color: #FFFFFF;
  margin-top: 5px;
  font-weight: bold;
  font-size: 1.em;
  font-size: 1.3em;
}
.menu li:hover {
  background-color: #FFFFFF;
  color: #2F4A67;
}
h3 {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div class="menu">

  <ul>

    <a href="#">
      <li>Home</li>
    </a>
    <a href="#">
      <li>Abot me</li>
    </a>



  </ul>

</div>
</header>
<div class="content">
<h3 style="display: block;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
</h3>
</div>

0

solved How to make scroll menu? [closed]