简体   繁体   English

javascript的scrollTo

[英]javascript for scrollTo

I have this script : 我有这个脚本:

$(document).ready(function() {  
        $('a.link').click(function () {  
            $('#wrapper').scrollTo($(this).attr('href'), 400);
            $('a.link').removeClass('selected');  
            $(this).addClass('selected');
            return false;  
        });  
    });
    function setPosition(check, div, p1, p2, p3, p4, p5) {
    if(check==='#box1')
        {
            $(div).scrollTo(p1, 400);
        }
    else if(check==='#box2')
        {
            $(div).scrollTo(p2, 400);
        }
    else if(check==='#box3')
        {
            $(div).scrollTo(p3, 400);
        }
    else if(check==='#box4')
        {
            $(div).scrollTo(p4, 400);
        }
    else
        {
            $(div).scrollTo(p5, 400);
        }
    };

but for box4and box 5, thats won't slide to left . 但是对于box4和box 5来说,那不会滑到左边。 that slide to bottom of box1 . 滑到box1的底部。 so the layout be like this : 所以布局是这样的:

_____________________________________________________________________
|              |                 |                 |                |
|              |                 |                 |                |
|     box1     |      box2       |       box3      |      box4      |
|              |                 |                 |                | 
|______________|_________________|_________________|________________|
|              |                 |                 |                |
|              |                 |                 |                |
|    box5      |      box6       |      box7       |      box8      |
|              |                 |                 |                |
|______________|_________________|_________________|________________|

I wont the page all stright to right not go down . 我不会把所有页面都正确地往下走。 anysugest ? 有糖水吗? how can I change it ? 我该如何更改? thank you very much for all advice or suggest. 非常感谢您的所有建议或建议。

Is this what you are looking for? 这是你想要的? http://jsfiddle.net/6cmjz/ (notice the scrollbar on the bottom) http://jsfiddle.net/6cmjz/ (请注意底部的滚动条)

Simply set a width to your wrapper. 只需为包装器设置宽度即可。

#wrapper{
   width: 1000px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM