如何向下滚动 - JQuery

时间:2012-09-29 05:22:30

标签: javascript jquery

我不是程序员,但我使用下面的代码将页面滚动到顶部。

如何调整它以向下滚动?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>

<a class="btnMedio" href="javascript:;">
    <img src="http://desmond.imageshack.us/Himg41/scaled.php?server=41&filename=deixeseuemail.png&res=landing"/>
</a>

<script>
    $('.btnMedio').click(function(){
        $('html, body').animate({scrollTop:1000},'50');
    });
</script>

5 个答案:

答案 0 :(得分:51)

$('.btnMedio').click(function(event) {
    // Preventing default action of the event
    event.preventDefault();
    // Getting the height of the document
    var n = $(document).height();
    $('html, body').animate({ scrollTop: n }, 50);
//                                       |    |
//                                       |    --- duration (milliseconds) 
//                                       ---- distance from the top
});

答案 1 :(得分:15)

试试这个:

window.scrollBy(0,180); // horizontal and vertical scroll increments

答案 2 :(得分:8)

我主要使用以下代码向下滚动

$('html, body').animate({ scrollTop:  $(SELECTOR).offset().top - 50 }, 'slow');

答案 3 :(得分:7)

这可以用来解决这个问题

<div id='scrol'></div> 

在javascript中使用此

jQuery("div#scrol").scrollTop(jQuery("div#scrol")[0].scrollHeight);

答案 4 :(得分:0)

如果要向下滚动到div(id =“ div1”)。然后,您可以使用此代码。

$files = $request->filenames;

if($files) {
    foreach ($files as $u_file) {
        $name=$u_file->getClientOriginalName();
        $u_file->move(public_path().'/images/', $name);
        $project_file =File::where('project_id', $id)->first();

        $project_file->filename = $name;
        $project->files()->save($project_file);
    }
}