滚动到页面底部

时间:2012-07-30 11:49:42

标签: jquery

我面临的问题是,我的调查中有一系列问题。第一个问题要求用户单击复选框,如果他不是成员。如果用户选中该复选框,则光标应自动滚动到页面底部,跳过其后面的所有问题。

我使用jquery尝试了不同的功能但没有工作。 这是我之前尝试的代码(P.S也没有这样做)

  <?php
    if(!stristr($_SERVER['PHP_SELF'],"printSummary")) {
        require_once("../lib/include/common.inc.php");
    } else {
        require_once("../../lib/include/common.inc.php");
    }
    ob_start();

    $node_id = $parentnode?$parentnode:getDataFromSession("data,node_id");
    $node_name = get_node_name( $node_id,$_SESSION["survey"],$_SESSION['idLink']);
    $surveyForText = getText2("This survey is for:")." ".$node_name;

    if(strlen($node_name)>0) {
        echo "<script type='text/javascript'>";
        echo "$(document).ready(function(){";
        echo "$('.generalErrorMsg').first().addClass('generalErrorMsgWithMargin').text(\"$surveyForText\");";
        echo "});";
        echo "</script>";
    }
 //code that I am talking about starts here
    $currentPageNum = currentPageNumber();
    if($currentPageNum==4)
    {
        echo "<script type=\"text/javascript\">
        $(document).ready(function(){
            $('input[type=checkbox]').click(function() {
                alert('here');
                setTimeout(function() { 
                    window.scrollTo(0, 1) },100);
            }); 


            //window.scrollBy(100,100); // horizontal and vertical scroll increments
            //scrolldelay = setTimeout('pageScroll()',80); // scrolls every 80 milliseconds
        });";
        echo "</script>";
    }
    ?>

请帮我解决一下这个问题。提前致谢 -Jathin

2 个答案:

答案 0 :(得分:0)

你应该试试

scrollTop.

scrollTopDOM Object的属性。

但是在jQuery中有一个函数scrollTop(),所以你可以在jquery中使用。

喜欢$(window).scrollTop(100);

$('input[type=checkbox]').click(function() {
   alert('here');
   setTimeout(function() { 
      window.scrollTo(0, 1) },100);
});

更改为

$('input[type=checkbox]').click(function() {
   //alert('here');
   setTimeout(function() { 
      $(window).scrollTop(100);},100);
});

如果你有一个元素可以滚动 你可以试试

$(window.)scrollTop($('#elemenet-id').offset().top);

答案 1 :(得分:0)

由于php,html和javascript的混合,你的代码难以阅读 你最好只显示最终的html + javascript。 无论如何,如果你需要滚动窗口到文档的页脚 - $(document).scrollTop($(document).height())