【发布时间】:2017-05-05 10:44:29
【问题描述】:
我正在尝试在使用 Material Design Lite 制作的模板中进行无限滚动。我在 mdl-layout__container 中有 X 个 MDL 卡,每行三张卡,加载页面时首先显示三行。因此,当我单击一个按钮时,应将每行三张卡片的三行添加到页面中,然后无需再次单击该按钮以继续无限滚动下一行。这意味着只需单击一下即可在 mdl-layout__container 上开始无限滚动。
我的第一个想法是在 mdl-layout__content 下方添加一个新的“额外”div 以加载每个新行,但我不知道这是否是最好的方法。
这是我使用 3x3 网格的主要课程:
<main class="mdl-layout__content mdl-color--grey-100">
<div class="mdl-grid walla-content">
<!-- START Bucle to load every card, hand made by now -->
<div class="walla-cards mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing" id="1">
<div class="walla-updates mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--12-col-desktop">
<figure class="mdl-card__media">
<img src="images/chairs.jpg" alt="" />
</figure>
<div class="mdl-card__title mdl-card--expand mdl-color--teal-300">
<h2 class="mdl-card__title-text">Article 1</h2>
</div>
<div class="mdl-card__supporting-text mdl-color-text--grey-600">
Little description
</div>
<div class="mdl-card__actions mdl-card--border">
<a href="#" class="mdl-button mdl-js-button mdl-js-ripple-effect">See more</a>
</div>
</div>
<div class="walla-separator mdl-cell--1-col"></div>
</div>
<!-- Bucle to load every card, handmade by now END -->
<!-- Delete when proof concept finishes -->
<div class="walla-cards mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing" id="2">
<div class="walla-updates mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--12-col-desktop">
<figure class="mdl-card__media">
<img src="images/chairs.jpg" alt="" />
</figure>
<div class="mdl-card__title mdl-card--expand mdl-color--teal-300">
<h2 class="mdl-card__title-text">Article 1</h2>
</div>
<div class="mdl-card__supporting-text mdl-color-text--grey-600">
Little description
</div>
<div class="mdl-card__actions mdl-card--border">
<a href="#" class="mdl-button mdl-js-button mdl-js-ripple-effect">See more</a>
</div>
</div>
<div class="walla-separator mdl-cell--1-col"></div>
</div>
<div class="walla-cards mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing" id="3">
<div class="walla-updates mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--12-col-desktop">
<figure class="mdl-card__media">
<img src="images/chairs.jpg" alt="" />
</figure>
<div class="mdl-card__title mdl-card--expand mdl-color--teal-300">
<h2 class="mdl-card__title-text">Article 1</h2>
</div>
<div class="mdl-card__supporting-text mdl-color-text--grey-600">
Little description
</div>
<div class="mdl-card__actions mdl-card--border">
<a href="#" class="mdl-button mdl-js-button mdl-js-ripple-effect">See more</a>
</div>
</div>
<div class="walla-separator mdl-cell--1-col"></div>
</div>
<div class="walla-cards mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing" id="4">
<div class="walla-updates mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--12-col-desktop">
<figure class="mdl-card__media">
<img src="images/chairs.jpg" alt="" />
</figure>
<div class="mdl-card__title mdl-card--expand mdl-color--teal-300">
<h2 class="mdl-card__title-text">Article 1</h2>
</div>
<div class="mdl-card__supporting-text mdl-color-text--grey-600">
Little description
</div>
<div class="mdl-card__actions mdl-card--border">
<a href="#" class="mdl-button mdl-js-button mdl-js-ripple-effect">See more</a>
</div>
</div>
<div class="walla-separator mdl-cell--1-col"></div>
</div>
<div class="walla-cards mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing" id="5">
<div class="walla-updates mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--12-col-desktop">
<figure class="mdl-card__media">
<img src="images/chairs.jpg" alt="" />
</figure>
<div class="mdl-card__title mdl-card--expand mdl-color--teal-300">
<h2 class="mdl-card__title-text">Article 1</h2>
</div>
<div class="mdl-card__supporting-text mdl-color-text--grey-600">
Little description
</div>
<div class="mdl-card__actions mdl-card--border">
<a href="#" class="mdl-button mdl-js-button mdl-js-ripple-effect">See more</a>
</div>
</div>
<div class="walla-separator mdl-cell--1-col"></div>
</div>
<div class="walla-cards mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing" id="6">
<div class="walla-updates mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--4-col-tablet mdl-cell--12-col-desktop">
<figure class="mdl-card__media">
<img src="images/chairs.jpg" alt="" />
</figure>
<div class="mdl-card__title mdl-card--expand mdl-color--teal-300">
<h2 class="mdl-card__title-text">Article 1</h2>
</div>
<div class="mdl-card__supporting-text mdl-color-text--grey-600">
Little description
</div>
<div class="mdl-card__actions mdl-card--border">
<a href="#" class="mdl-button mdl-js-button mdl-js-ripple-effect">See more</a>
</div>
</div>
<div class="walla-separator mdl-cell--1-col"></div>
</div>
<div id="extra"></div>
</div>
</main>
<a href="#" id="view-source" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored mdl-color-text--white">Load More button</a>
我尝试将下一行添加到“额外”div:
$("#view-source").click(function () {
$("#extra").append("New div rows");
});
【问题讨论】:
-
当您说 “然后无需再次单击按钮以继续无限滚动下一行。” 您的意思是一旦单击了您拥有的每张卡片服务器(假设您有 1000 个)将立即加载?
-
谢谢@Alvaro。对不起,我不能很好地解释这一点。单击后,应该再加载六张卡片(两行),并且每次用户向下滚动页面时无需再次单击按钮,接下来的六张卡片应该被加载,依此类推
-
没问题!我认为这个问题更适合UX Stackexchange,如果您正在寻找的是背后的基本原理(而不是代码实现)并且可以以不同的方式完成(点击+滚动)。
标签: javascript jquery css material-design material-design-lite