Skip to content
Browse files

smooth scroll

make the anchors change automatically
  • Loading branch information...
1 parent 002b5cd commit 6073d0dd50de83e80cbd7234df5c0758210df2f7 @momolog momolog committed Aug 31, 2012
Showing with 22 additions and 18 deletions.
  1. +8 −11 index.php
  2. +14 −7 js/site.js
View
19 index.php
@@ -1,19 +1,16 @@
<?php include("mecode/kv/kv-code.php"); ?><!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>reecode</title>
-<? KV_header(); ?>
-<link href="css/style.css" rel="stylesheet" type="text/css" />
-<script type="text/javascript" src="js/cs.js"></script>
-<script type="text/javascript">
- function initAll(){
- initRolloverImgs();
- }
-</script>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>reecode</title>
+ <? KV_header(); ?>
+ <link href="css/style.css" rel="stylesheet" type="text/css" />
+ <script type="text/javascript" src="js/cs.js"></script>
+ <script type="text/javascript" src="js/waypoints.min.js"></script>
+ <script type="text/javascript" src="js/site.js"></script>
</head>
-<body onLoad="initAll()">
+<body>
<table style="width: 100%; height: 100%" cellpadding="0" cellspacing="0" marginwidth="0" marginheight="0" border="0">
<tr><td style="background-image:url(img/Bg_120510.jpg); background-attachment:fixed; background-repeat:no-repeat; background-position:center">
<table cellpadding="0" cellspacing="0" border="0">
View
21 js/site.js
@@ -30,22 +30,29 @@ jQuery(function($) {
scrollElement = this.nodeName.toLowerCase();
$(this).attr('scrollTop', initScrollTop);
return false;
- }
+ }
});
+ $("a[name]")
+ .waypoint()
+ .bind('waypoint.reached', function(e){ window.location.hash = '#'+e.target.name })
+
+
// Smooth scrolling for internal links
- $("a[href^='#']").click(function(event) {
+ $("a[href^='#']")
+ .click(function(event) {
event.preventDefault();
- var $this = $(this),
- target = this.hash,
- $target = $(target);
+ var hash = this.hash;
+ var $target = $('a[name='+hash.substr(1)+']').first();
$(scrollElement).stop().animate({
- 'scrollTop': $target.offset().top
+ 'scrollTop': $target.offset().top - 30
}, 500, 'swing', function() {
- window.location.hash = target;
+ window.location.hash = hash;
});
});
+
+ initRolloverImgs();
});

0 comments on commit 6073d0d

Please sign in to comment.
Something went wrong with that request. Please try again.