W3 Mind Logo
Home » Stick or fix DIV at top after scrolling

Stick or fix DIV at top after scrolling

				
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(window).scroll(function(){
      if ($(this).scrollTop() > 320) {
          $('.scroll-div').addClass('fixed');
      } else {
          $('.scroll-div').removeClass('fixed');
      }
  });
</script>
<style>
.scroll-div{background:#333;width:1000px;margin:0 auto;height:100px;}
.fixed{position:fixed;top:0;width:100%;left:0;}
</style>
</head>
<body>
<div class="scroll-div">Scrolling DIV</div>
</body>
</html>
				
			
About Author
Picture of W3Mind

W3Mind

W3Mind focuses on Blogging, Make Money Online, SEO, Business Blogging, Social Media, WordPress, Internet Tools, Web Design and Development.
Give it a Share
Facebook
Twitter
LinkedIn
You May Also Like
How to
START A
BLOG
(step by step)
Load WordPress Sites in as fast as 37ms!