Прокрутите один div медленнее, чем другой, используя CSS или JS - PullRequest
0 голосов
/ 21 июня 2020

У меня текст переведен на sh англи и латынь. Я хотел бы отображать как английский sh, так и латынь рядом в столбцах. Часто текст на английском sh содержит больше символов и слов, чем в латинском. Я бы хотел, чтобы столбец Latin прокручивался медленнее, чем столбец Engli sh, чтобы пользователь достигал последней строки обоих текстов одновременно.

Вот пример кода и пример пера .

Возможно ли это как-то с использованием CSS или JS? Я безуспешно искал. Заранее спасибо!

.col {
  width: 45%;
  margin: 2%;
  float: left;
}
<div class="container">
  <div class="col">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

</div>
  <div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in ligula ex. Aenean tempor metus eu ultrices efficitur. Curabitur at elementum metus. Donec facilisis eros sed volutpat dictum. Morbi pharetra sit amet est at interdum. Cras vitae nulla cursus, posuere leo ut, lacinia neque. Pellentesque hendrerit neque pulvinar gravida egestas. Aenean tempor metus eu ultrices efficitur. Curabitur at elementum metus. Donec facilisis eros sed volutpat dictum. Morbi pharetra sit amet est at interdum. Cras vitae nulla cursus, posuere leo ut, lacinia neque. </div>
</div>

Ответы [ 2 ]

1 голос
/ 21 июня 2020

Это то, что вы ищете?

let containerHeight = 200;
let ratio = parseFloat($("#col1")[0].scrollHeight - containerHeight) / parseFloat($("#col2")[0].scrollHeight - containerHeight);

$("#col1").on("scroll", () => {
  $("#col2").scrollTop($("#col1").scrollTop() / ratio);
});
.container {
  height: 200px;
  border: solid 1px #000;
  width: 200px;
  margin: 2%;
  overflow: scroll;
  float: left;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container" id="col1">
  <div>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less
    normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem
    ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
  </div>
</div>
<div class="container" id="col2">
  <div>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec in ligula ex. Aenean tempor metus eu ultrices efficitur. Curabitur at elementum metus. Donec facilisis eros sed volutpat dictum. Morbi pharetra sit amet est at interdum. Cras vitae nulla cursus,
    posuere leo ut, lacinia neque. Pellentesque hendrerit neque pulvinar gravida egestas. Aenean tempor metus eu ultrices efficitur. Curabitur at elementum metus. Donec facilisis eros sed volutpat dictum. Morbi pharetra sit amet est at interdum. Cras
    vitae nulla cursus, posuere leo ut, lacinia neque.
  </div>
</div>
0 голосов
/ 21 июня 2020

Попробуйте это

.col {
   overflow-y: scroll;
   height: 200px;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...