Live site.
我决定在我的新主题中加入javascript;这是我第一次这样做,并通过博客和论坛将我的想法拼凑起来。我将javascript放在标记中,而不是函数中。php。我注意到,在由javascript控制的导航之后,网站停止加载,这让我相信这就是问题所在,我只是不知道如何准确地找出到底是什么导致了问题。非常感谢您的帮助。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo(\'html_type\'); ?>; charset=<?php bloginfo(\'charset\'); ?>" />
<meta name="generator" content="Wordpress <?php bloginfo(\'version\'); ?>" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php bloginfo(\'name\'); ?> <?php wp_title(); ?></title>
<link rel="pingback" href="<?php bloginfo(\'pingback url\'); ?>" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo(\'rss2_url\'); ?>" />
<link rel="stylesheet" href="<?php bloginfo(\'stylesheet_url\'); ?>" />
<link rel="shortcut icon" href="<?php bloginfo(\'stylesheet_directory\'); ?>/favicon.ico" />
<?php wp_head(); ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(window).load(function(event) {
$(\'#Nav a\').click(function() {
$(\'#Nav li\').removeClass();
$(this).parent().addClass("current");
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([\'_setAccount\', \'UA-32783537-1\']);
_gaq.push([\'_trackPageview\']);
(function() {
var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;
ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script>
$(document).ready(function() {
function filterPath(string) {
return string
.replace(/^\\//,\'\')
.replace(/(index|default).[a-zA-Z]{3,4}$/,\'\')
.replace(/\\/$/,\'\');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement(\'html\', \'body\');
$(\'a[href*=#]\').each(function() {
var thisPath = filterPath(this.pathname) || locationPath;
if ( locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,\'\') ) {
var $target = $(this.hash), target = this.hash;
if (target) {
var targetOffset = $target.offset().top;
$(this).click(function(event) {
event.preventDefault();
$(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
location.hash = target;
});
});
}
}
});
// use the first element that is "scrollable"
function scrollableElement(els) {
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
var el = arguments[i],
$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>
<script>
$(function() {
$.fn.scrollBottom = function() {
return $(document).height() - this.scrollTop() - this.height();
};
var $el = $(\'#nav>div\');
var $window = $(window);
var top = $el.parent().position().top;
$window.bind("scroll resize", function() {
var gap = $window.height() - $el.height() - 10;
var visibleFoot = 340 - $window.scrollBottom();
var scrollTop = $window.scrollTop()
if (scrollTop < top + 10) {
$el.css({
top: (top - scrollTop) + "px",
bottom: "auto"
});
} else if (visibleFoot > gap) {
$el.css({
top: "auto",
bottom: visibleFoot + "px"
});
} else {
$el.css({
top: 0,
bottom: "auto"
});
}
}).scroll();
});
</script>
</head>