Sticky div

Developer
Size
2,225 Kb
Views
12,144

How do I make an sticky div?

Sticky div. What is a sticky div? How do you make a sticky div? This script and codes were developed by Kanha Sahu on 29 December 2022, Thursday.

Sticky div Previews

Sticky div - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>sticky div</title> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-latest.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<section class="container">
<div id="content" class="row"> <span class="col-xs-3" id="sidebar"> <div id="catcher"> This is the "catcher" <code>div</code> </div> <div id="sticky" style="position: fixed; top: 0px;"> This is the "sticky" <code>div</code> </div> </span> <span class="col-xs-9" style="background:#cccccc;"> Content <br><br><br> Content <br><br><br> Content <br><br><br> Content <br><br><br> Content <br><br><br> Content <br><br><br> Content <br><br><br> Content <br><br><br> Content <br><br><br> Content <br><br><br> Content <br><br><br> </span>
</div>
</section> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"'></script> <script src="js/index.js"></script>
</body>
</html>

Sticky div - Script Codes CSS Codes

body{height:2000px;}
#sidebar{}
#catcher{ background:#ff0066; padding:5px 8px; margin:10px auto; box-shadow:0 0 2px #e8e8e8; -moz-box-shadow:0 0 2px #e8e8e8; -webkit-box-shadow:0 0 2px #e8e8e8; -o-box-shadow:0 0 2px #e8e8e8; -ms-box-shadow:0 0 2px #e8e8e8;
}
#sticky{ background:#FAFAFA; padding:5px 8px; margin:0px auto; box-shadow:0 0 2px #e8e8e8; -moz-box-shadow:0 0 2px #e8e8e8; -webkit-box-shadow:0 0 2px #e8e8e8; -o-box-shadow:0 0 2px #e8e8e8; -ms-box-shadow:0 0 2px #e8e8e8;}

Sticky div - Script Codes JS Codes

$(document).ready(function() { function isScrolledTo(elem) { var docViewTop = $(window).scrollTop(); //num of pixels hidden above current screen var docViewBottom = docViewTop + $(window).height(); var elemTop = $(elem).offset().top; //num of pixels above the elem var elemBottom = elemTop + $(elem).height(); return ((elemTop <= docViewTop)); } var catcher = $('#catcher'); var sticky = $('#sticky'); $(window).scroll(function() { if(isScrolledTo(sticky)) { sticky.css('position','fixed'); sticky.css('top','0px'); }	var stopHeight = catcher.offset().top + catcher.height();	if ( stopHeight > sticky.offset().top) { sticky.css('position','absolute'); sticky.css('top',stopHeight); } }); });
Sticky div - Script Codes
Sticky div - Script Codes
Home Page Home
Developer Kanha Sahu
Username kaslab
Uploaded December 29, 2022
Rating 3
Size 2,225 Kb
Views 12,144
Do you need developer help for Sticky div?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Kanha Sahu (kaslab) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!