Skip to content

Instantly share code, notes, and snippets.

@ElijahGartin
Created December 7, 2012 17:38
Show Gist options
  • Save ElijahGartin/4234968 to your computer and use it in GitHub Desktop.
Save ElijahGartin/4234968 to your computer and use it in GitHub Desktop.
Fixed Div jQuery Scrolling Script
<!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" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script>
//<![CDATA[
$(window).load(function(){
var $sdiv = $("#mydiv");
$(window).scroll(function() {
$sdiv.stop().animate({
"marginTop": ($(window).scrollTop() + 50) + "px"
}, "slow");
});
});//]]>
</script>
</head>
<body>
<div id="mydiv"></div>
</body>
</html>
/* CSS definition file containing sitestyle stylesheets */
/********************************************
CSS Styles
Author : Elijah Gartin
Date: 06Aug2012
Updated: 18Sept2012
********************************************/
/*---*---*---*---*---*---*---*---*---*---*---
Organization Layout
*---*---*---*---*---*---*---*---*---*---*---*/
body {
height: 2000px;
}
#mydiv{
background: red;
width: 100px;
height: 100px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment