如何设置div的滚动位置并使其内部溢出? [英] How to set the scroll position of a div with a div overflowing inside it?

查看:48
本文介绍了如何设置div的滚动位置并使其内部溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个非常简单的html文档中包含以下html.

I have the following html in a really simple html document.

<div id="doublescroll_projects">
  <div class="project_icons">
    <div id="project" class="project_1"></div>
    <div id="project" class="project_2"></div>
    <div id="project" class="project_3"></div>
  </div>
</div>

然后,我有这个CSS:

Then, I have this css:

#doublescroll_projects {
   position:absolute;
     bottom:0px;
     right:0px;

   overflow:auto;
   width:900px;
   height:500px;
 }
    .project_icons {
       width:1500px;
       max-height:2000px;
 }

#project {
    height:240px;
    width:360px;
    float:left;
    margin:50px 55px 55px 50px;
}

project_icons类使doublescroll_projects div可在两个方向上滚动.我想将滚动位置设置为页面加载时垂直滚动一半和水平滚动一半.

The project_icons class makes the doublescroll_projects div scrollable in both directions. I want to set the scroll position to be half way scrolled vertically and halfway horizontally on the page load.

我查看了许多设置滚动条"问题和答案,但找不到任何解决方法,或者至少对我没有帮助.如果我有一个遗漏的问题,请告诉我,否则我将如何做?

I've looked at as many "set scrollbar" questions and answers I could find but nothing worked, or at least worked for me. If theres a question that I missed please let me know, otherwise how would I do this?

推荐答案

您不能使用纯CSS做到这一点.您需要使用js/jQuery,例如:

you can't do it with pure CSS. You need to use js/jQuery, for example:

$('#doublescroll_projects').scrollLeft(50);
$('#doublescroll_projects').scrollTop(50);

https://api.jquery.com/scrollleft/

https://api.jquery.com/scrollTop/

这篇关于如何设置div的滚动位置并使其内部溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆