jquery选择

时间:2009-10-25 03:51:57

标签: jquery ajax css-selectors

我有以下代码:

$(document).ready(function() {

 var hash = window.location.hash.substr(1);
 var href = $('#nav li a').each(function(){
  var href = $(this).attr('href');
  if(hash==href.substr(0,href.length-5)){
   var toLoad = hash+'.html #content';
   $('#content').load(toLoad)
  }           
 });

 $('#nav li a').click(function(){

  var toLoad = $(this).attr('href')+' #content';
  $('#content').slideUp(2000,loadContent);
  window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
  function loadContent() {
   $('#content').load(toLoad,'',showNewContent())
  }
  function showNewContent() {
   $('#content').slideDown(2000,hideLoader());
  }
  function hideLoader() {
   $('#load').fadeOut('normal');
  }
  return false;

 });

 });

感谢nettuts一个非常好的简洁和强大的编码(在我看来)

我有上下滑动的问题,它关闭很好,但由于每个内容部分加载时高度不同,它打开到旧的高度并捕捉到新的高度,我怎么能绕过这个?

还能以任何方式添加浏览器后退/前进按钮功能吗?我还没有看过这个,但无论如何都可能要回来问这个问题!

1 个答案:

答案 0 :(得分:1)

如果您在slideDown之前加载新内容,它应该直接向下滑动到当前内容,而不是旧内容。为了使你的后退和前进按钮工作,你需要一个历史插件。 jQuery BBQ可能是这方面最好的。