doufang3001 2015-06-11 07:54
浏览 64
已采纳

阅读更多按钮或显示/隐藏的PHP

I want to show only e.g. 200 words from post with show/hide button to show whole post and hide post to 200 words. Text is on variable I don't know how to do this. I tried with javascript but I can't hide content of post.

here's the:

<div id="test">content</div>
<script>
    var str = "<?=$row[3]?>"; 
    var test = str.substr(0, 700);
    document.getElementById('test').innerHTML = test;
</script>
<p id="demo"></p>
<script>
    function myFunction() {
        var str = "<?=$row[3]?>"; 
        var test = str.substr(700);
        document.getElementById("demo").innerHTML = test;
    }
</script>
<button onclick="myFunction()">Click me</button>
  • 写回答

2条回答 默认 最新

  • dongwen5870 2015-06-11 08:05
    关注

    You can do that in simple css

    Don't need any other

    hide your overflow text

    modify code in css according to your need

    /* css only show/hide
    
     */
    
    html { background: white }
    
    * {
        margin: 0;
        padding: 0;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        -ms-box-sizing: border-box;
        box-sizing: border-box;
    }
    
    figure {
        margin: 0 0 1.3rem 0;
        -webkit-transition: .125s linear;
        -moz-transition: .125s linear;
        -ms-transition: .125s linear;
        -o-transition: .125s linear;
        transition: .125s linear;
    }
    
    figure img {
        max-width: 100%;
        height: auto;
    }
    
    body {
        max-width: 480px;
        width: 90%;
        margin: 3em auto;
        font-size: 75%;
        line-height: 1.3rem;
        font-family: sans-serif;
        position: relative;
        *zoom: 1;
    }
    
    body:before, body:after {
        content: "";
        display: table;
    }
    
    body:after { clear: both }
    
    p { margin-bottom: 1.3rem }
    
    article {
        margin-bottom: 3rem;
        position: relative;
        *zoom: 1;
    }
    
    article:before, article:after {
        content: "";
        display: table;
    }
    
    article:after { clear: both }
    
    article figure {
        float: left;
        width: 32.5%;
    }
    
    article section:first-of-type {
        float: right;
        width: 62.5%;
    }
    
    article section:last-of-type {
        display: none;
        visibility: hidden;
    }
    
    section {
        -webkit-transition: .125s linear;
        -moz-transition: .125s linear;
        -ms-transition: .125s linear;
        -o-transition: .125s linear;
        transition: .125s linear;
    }
    
    input[type=checkbox] {
        border: 0;
        clip: rect(0 0 0 0);
        height: 1px;
        width: 1px;
        margin: -1px;
        overflow: hidden;
        padding: 0;
        position: absolute;
    }
    
    [for="read_more"] {
        position: absolute;
        bottom: -3rem;
        left: 0;
        width: 100%;
        text-align: center;
        padding: .65rem;
        box-shadow: inset 1px 1px rgba(0, 0, 0, 0.1), inset -1px -1px rgba(0, 0, 0, 0.1);
    }
    
    [for="read_more"]:hover {
        background: rgba(0,0,0,.5);
        color: rgb(255,255,255);
    }
    
    [for="read_more"] span:last-of-type {
        display: none;
        visibility: hidden;
    }
    
    input[type=checkbox]:checked ~ section {
        display: block;
        visibility: visible;
        width: 100%;
    }
    
    input[type=checkbox]:checked ~ figure { width: 100% }
    
    input[type=checkbox]:checked ~ [for="read_more"] span:first-of-type {
        display: none;
        visibility: hidden;
    }
    
    input[type=checkbox]:checked ~ [for="read_more"] span:last-of-type {
        display: block;
        visibility: visible;
    }
    <article>
        
    
        <input type="checkbox" id="read_more" role="button">
        <label for="read_more" onclick=""><span>Read More</span><span>Hide This Shit!</span></label>     
          
        <figure>
            <img src="http://www.surprisegiftz.com/images/media/ceramicphototiles.jpg" alt="Example text" />
        </figure>
    
        <section>
        <p>The function of a paragraph is to mark a pause, setting the paragraph apart from what precedes it. If a paragraph is preceded by a title or subhead, the indent is superfluous and can therefore be omitted</p>
        </section>    
    
    
    
    <section>
        <p>The function of a paragraph is to mark a pause, setting the paragraph apart from what precedes it. If a paragraph is preceded by a title or subhead, the indent is superfluous and can therefore be omitted</p>
        <p>The function of a paragraph is to mark a pause, setting the paragraph apart from what precedes it. If a paragraph is preceded by a title or subhead, the indent is superfluous and can therefore be omitted</p>
    
    </section>
    
    </article>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路