2011-05-18 26 views
0

如何從jquery ajax句柄頁面使用jquery scrolltop?如何從jquery ajax句柄頁面使用jquery scrolltop?

aa.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.scrollTo-min.js"></script>   
<script type="text/javascript">  
    jQuery(document).ready(function(){ 
     $.ajax({ 
      url: "bb.php", 
      dataType: "html", 
      type: 'POST', 
      data: "word=hello", 
      success: function(data){ 
       $("#result").html(data); 
      } 
      }); 
     }); 
</script> 
<script type="text/javascript"> 
    jQuery(document).ready(function(){ 
     $(".scrolltoanchor").click(function() { 
     $.scrollTo($($(this).attr("href")), { 
      duration: 750 
     }); 
     return false; 
    }); 
    }); 
</script> 
</head> 
<body id="body"> 
<div style="padding-top:600px;">jquery scrollto test</div> 
<div id="result" style="padding-top:600px;"></div> 
<div style="padding-top:600px;"> 
    <a class="scrolltoanchor" href="#body">back to top</a><!-- this can scroll to the top via jquery.scrollTo function --> 
</div> 
</body> 
</html> 

bb.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" dir="ltr" lang="en-US"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head> 
<body> 
<a class="scrolltoanchor" href="#body"><?php echo $_POST['word']; ?>: back to the top</a>!-- this can't scroll to the top via jquery.scrollTo function, just run aa.html?#body as a html anchor --> 
</body> 
</html> 

那麼,如何添加scrollTop的在bb.php,以便它可以scrollto的aa.html的頂部有一個動畫?謝謝。

回答

1

你應該把它放在AJAX成功函數中。

編輯:你也不是真的想在你的ajax頁面中輸入文字,頭部等。

+0

kingjiv,對,忘了這個,thx。 – cj333 2011-05-18 20:13:03