本文介绍了如何为HTML / CSS页面添加更多按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个单页网站,它将有巨大的内容。假设它上面有1000张照片。我不希望人们等待5分钟来加载我的页面。所以我想在页面底部添加LOAD MORE按钮。

I want to make a single page website and it will have huge content. Suppose it has 1000 photos on it. I don't want people to wait 5 minutes to load my page. So I wanna add LOAD MORE button on the page bottom.

如何使用HTML / CSS / JS?

How to do that with HTML/CSS/JS?

推荐答案

您可以将所有 div s设置为 display:none; 首先,然后使用jQuery显示前10(或许多你想显示):

You could set all the divs' to display:none; at first and then use jQuery to show the first 10 (or however many you wish to show):

$(function(){
    $("div").slice(0, 10).show(); // select the first ten
    $("#load").click(function(e){ // click event for load more
        e.preventDefault();
        $("div:hidden").slice(0, 10).show(); // select next 10 hidden divs and show them
        if($("div:hidden").length == 0){ // check if any hidden divs still exist
            alert("No more divs"); // alert if there are none left
        }
    });
});

这可以节省你在需要几行代码时可以包含整个插件的麻烦。

This saves you the trouble of including an entire plugin when what you want can be achieved in a few lines of code.

这篇关于如何为HTML / CSS页面添加更多按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 15:51