欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

純 CSS 實(shí)現(xiàn)點(diǎn)擊展開(kāi)閱讀全文功能

  發(fā)布時(shí)間:2020-10-13 16:44:54   作者:MedusaSorcerer   我要評(píng)論
這篇文章主要介紹了純 CSS 實(shí)現(xiàn)【點(diǎn)擊展開(kāi)閱讀全文】功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

記要

開(kāi)發(fā)文章展示列表界面時(shí), 想通過(guò)展示部分文章頭內(nèi)容達(dá)到基本信息概覽的需求即可, 并展示 【點(diǎn)擊展開(kāi)閱讀全文】 的按鈕以獲取詳情內(nèi)容。

參考了文章 caibaojian.com/css-tonggle… 的純 CSS 的想法, 但文章描述的內(nèi)容適用于單篇文章的效果, 而在使用 <li></li> 標(biāo)簽生成表數(shù)據(jù)的情況下并不友好, 所以在此基礎(chǔ)上進(jìn)行了相對(duì)應(yīng)的優(yōu)化, 具體代碼如下:

<div>
    <ul id="content-ul">
        <!-- 這是存放文章內(nèi)容 LI 標(biāo)簽的標(biāo)簽體 -->
    </ul>
</div>
[id^="contTab"] {
    display: none;
}

.content-more {
    display: none;
}

[id^="contTab"]:checked ~ #content {
    max-height: 95px;
    overflow: hidden;
}

[id^="contTab"]:checked ~ .content-more {
    display: block;
    position: relative;
    text-align: center;
}

[id^="contTab"]:checked ~ .content-more .gradient {
    background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0)), to(#fff));
    background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0), #fff);
    background-image: linear-gradient(-180deg, rgba(255, 255, 255, 0), #fff);
    height: 80px;
    position: absolute;
    left: 0;
    top: -79px;
    width: 100%;
}

[id^="contTab"]:checked ~ .content-more .readmore {
    display: inline-block;
    background: #319a1717;
    color: #0014ff9e;
    width: 300px;
    height: 30px;
    border-radius: 32px;
    line-height: 32px;
    font-size: 14px;
    cursor: pointer;
    text-indent: 0;
}

當(dāng)然了, 這兒附上一段 JS 的代碼:

function inner(response) {
    for (var val of response.data) {
        document.getElementById('content-ul').innerHTML += '' +
            '<li>' +
            '<h2 class="title">' + val.title + '</h2>' +
            '<p class="update_author">' + val.author_name + ' / ' + layui.util.toDateString(val.update, "yyyy-MM-dd HH:mm:ss") + '</p>' +
            '<input type="checkbox" id="contTab_' + val.id + '" checked="checked" class="tabbed">' +
            '<div id="content">' + val.content + '</div>' +
            '<div class="content-more"><div class="gradient"></div> <label for="contTab_' + val.id + '" class="readmore">點(diǎn) 擊 查 閱 全 文</label></div>' +
            '</li>'
    }
}

說(shuō)明

改善的方式是將綁定的標(biāo)簽 ID 屬性使用動(dòng)態(tài)的方式生成并綁定, 其次使用 CSS 選擇器, 使用的是模糊匹配的方式, 不局限于某個(gè)具體的 ID 選擇器。

源碼

該代碼片段是應(yīng)用于 M&OAS 項(xiàng)目中, 你可以 點(diǎn)擊這里 查看相關(guān)的代碼信息, 獲得更加完整的代碼。

PS:如果你進(jìn)去了居然發(fā)現(xiàn)沒(méi)有相關(guān)的代碼塊, 不要驚慌, 可能我還沒(méi)有上傳到 GITHU 上, 多多包涵 QAQ ~

腦子是個(gè)好東西, 哈哈哈哈哈哈~

到此這篇關(guān)于純 CSS 實(shí)現(xiàn)【點(diǎn)擊展開(kāi)閱讀全文】功能的文章就介紹到這了,更多相關(guān)css點(diǎn)擊展開(kāi)閱讀全文內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論