Template:Queens Canada/Header

From 2011.igem.org

(Difference between revisions)
Line 21: Line 21:
<!--smooth scrolling-->
<!--smooth scrolling-->
-
 
+
<link rel="stylesheet" href="css/style.css" />
-
<link rel="stylesheet" href="css/style.css" />
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script>
<script>
-
$(document).ready(function() {
+
$(function() {
-
  function filterPath(string) {
+
-
  return string
+
function filterPath(string) {
-
    .replace(/^\//,'')
+
return string
-
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
+
.replace(/^\//,'')
-
    .replace(/\/$/,'');
+
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
-
  }
+
.replace(/\/$/,'');
-
  var locationPath = filterPath(location.pathname);
+
}
-
  var scrollElem = scrollableElement('html', 'body');
+
-
 
+
var locationPath = filterPath(location.pathname);
-
  $('a[href*=#]').each(function() {
+
var scrollElem = scrollableElement('html', 'body');
-
    var thisPath = filterPath(this.pathname) || locationPath;
+
-
    if (  locationPath == thisPath
+
// Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
-
    && (location.hostname == this.hostname || !this.hostname)
+
$('a[href*=#]').each(function() {
-
    && this.hash.replace(/#/,'') ) {
+
-
      var $target = $(this.hash), target = this.hash;
+
// Ensure it's a same-page link
-
      if (target) {
+
var thisPath = filterPath(this.pathname) || locationPath;
-
        var targetOffset = $target.offset().top;
+
if (  locationPath == thisPath
-
        $(this).click(function(event) {
+
&& (location.hostname == this.hostname || !this.hostname)
-
          event.preventDefault();
+
&& this.hash.replace(/#/,'') ) {
-
          $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
+
-
            location.hash = target;
+
// Ensure target exists
-
          });
+
var $target = $(this.hash), target = this.hash;
-
        });
+
if (target) {
-
      }
+
-
    }
+
// Find location of target
-
  });
+
var targetOffset = $target.offset().top;
-
 
+
$(this).click(function(event) {
-
  // use the first element that is "scrollable"
+
-
  function scrollableElement(els) {
+
// Prevent jump-down
-
    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
+
event.preventDefault();
-
      var el = arguments[i],
+
-
          $scrollElement = $(el);
+
// Animate to target
-
      if ($scrollElement.scrollTop()> 0) {
+
$(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
-
        return el;
+
-
      } else {
+
// Set hash in URL after animation successful
-
        $scrollElement.scrollTop(1);
+
location.hash = target;
-
        var isScrollable = $scrollElement.scrollTop()> 0;
+
-
        $scrollElement.scrollTop(0);
+
});
-
        if (isScrollable) {
+
});
-
          return el;
+
}
-
        }
+
}
-
      }
+
-
    }
+
});
-
    return [];
+
-
  }
+
// Use the first element that is "scrollable" (cross-browser fix?)
-
 
+
function scrollableElement(els) {
-
});
+
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
-
 
+
var el = arguments[i],
-
</script>
+
$scrollElement = $(el);
 +
if ($scrollElement.scrollTop()> 0) {
 +
return el;
 +
} else {
 +
$scrollElement.scrollTop(1);
 +
var isScrollable = $scrollElement.scrollTop()> 0;
 +
$scrollElement.scrollTop(0);
 +
if (isScrollable) {
 +
return el;
 +
}
 +
}
 +
}
 +
return [];
 +
}
 +
 +
});
 +
</script>

Revision as of 05:54, 28 September 2011