jquery實(shí)現(xiàn)點(diǎn)擊查看更多內(nèi)容控制段落文字展開折疊效果
本文實(shí)例講述了jquery實(shí)現(xiàn)點(diǎn)擊查看更多內(nèi)容控制段落文字展開折疊效果。分享給大家供大家參考。具體如下:
這里使用jQuery實(shí)現(xiàn)的文字展開折疊效果,點(diǎn)擊文字后文字內(nèi)容會(huì)完整的顯示出來(lái),控制段落來(lái)顯示文字,不需要的時(shí)候,可以再次點(diǎn)擊后將內(nèi)容折疊起來(lái),也就是隱藏了一部分內(nèi)容。點(diǎn)擊查看更多的功能,在很多大網(wǎng)站都有在用,像一些電影簡(jiǎn)介、產(chǎn)品介紹有時(shí)候?yàn)榱隧?yè)面的布局效果,常常默認(rèn)是隱藏了一部分,用戶想看的時(shí)候可以點(diǎn)擊后展開。
運(yùn)行效果如下圖所示:
具體代碼如下:
<!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jQuery文本段落展開和折疊效果</title> <style> html,body,div,h2,p{margin: 0;padding: 0;} html{font: 1em Arial, Helvetica, sans-serif;color: #444;} a{color: #0087f1;} p{margin-bottom: 5px;} #container{margin: 0 auto;width: 600px;} #container h2{font-size: 20px;color: #0087f1;} #wrap{position: relative;padding: 10px;overflow: hidden;} #gradient{width: 100%;height: 35px;background: url() repeat-x;position: absolute;bottom: 0;left: 0;} #read-more{padding: 5px;border-top: 4px double #ddd;background: #fff;color: #333;} #read-more a{padding-right: 22px;background: url() no-repeat 100% 50%;font-weight: bold;text-decoration: none;} #read-more a: hover{color: #000;} </style> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(function(){ var slideHeight = 75; // px var defHeight = $('#wrap').height(); if(defHeight >= slideHeight){ $('#wrap').css('height' , slideHeight + 'px'); $('#read-more').append('<a href="#">點(diǎn)擊查看更多。。</a>'); $('#read-more a').click(function(){ var curHeight = $('#wrap').height(); if(curHeight == slideHeight){ $('#wrap').animate({ height: defHeight }, "normal"); $('#read-more a').html('點(diǎn)擊隱藏'); $('#gradient').fadeOut(); }else{ $('#wrap').animate({ height: slideHeight }, "normal"); $('#read-more a').html('點(diǎn)擊查看更多。。'); $('#gradient').fadeIn(); } return false; }); } }); </script> </head> <body> <div id="container"> <h1>jQuery 控制段落文字展開折疊,點(diǎn)擊查看更多的功能</h1> <h2>About Billabong</h2> <div id="wrap"> <div> <p>Gordon developed his own stitching technique, which made the garments more durable, cost effective and less labor intensive. He employed machinists, moved the operation into a factory, set up a distribution network and sponsored a team of renowned Australian surfers. The business thrived.</p> <p>Since those beginnings, Billabong has expanded its product range to include boardsport products such as wetsuits, watches, surfboards, snowboard outerwear and skateboarding apparel.</p> </div> <div id="gradient"></div> </div> <div id="read-more"></div> </div> </body> </html>
希望本文所述對(duì)大家的jquery程序設(shè)計(jì)有所幫助。
- jQuery實(shí)現(xiàn)DIV響應(yīng)鼠標(biāo)滑過(guò)由下向上展開效果示例【測(cè)試可用】
- jquery控制頁(yè)面的展開和隱藏實(shí)現(xiàn)方法(推薦)
- 基于jQuery實(shí)現(xiàn)下拉收縮(展開與折疊)特效
- jQuery實(shí)現(xiàn)DIV層收縮展開的方法
- jquery實(shí)現(xiàn)可點(diǎn)擊伸縮與展開的菜單效果代碼
- jQuery實(shí)現(xiàn)文本展開收縮特效
- jQuery實(shí)現(xiàn)表格展開與折疊的方法
- jquery實(shí)現(xiàn)先淡出再折疊收起的動(dòng)畫效果
- jQuery使用slideUp方法實(shí)現(xiàn)控制元素緩慢收起
- jQuery實(shí)現(xiàn)的頁(yè)面詳情展開收起功能示例
相關(guān)文章
jQuery插件Validate實(shí)現(xiàn)自定義校驗(yàn)結(jié)果樣式
這篇文章主要介紹了jQuery插件Validate實(shí)現(xiàn)自定義校驗(yàn)結(jié)果樣式的方法,感興趣的小伙伴們可以參考一下2016-01-01詳解jQuery的animate動(dòng)畫方法及動(dòng)畫排隊(duì)問(wèn)題解決
這篇文章主要介紹了jQuery的animate動(dòng)畫方法及動(dòng)畫排隊(duì)問(wèn)題解決的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用jQuery,感興趣的朋友可以了解下2021-05-05動(dòng)態(tài)獲取復(fù)選框checkbox選中個(gè)數(shù)的jquery代碼
這篇文章主要介紹了jquery中動(dòng)態(tài)獲取復(fù)選框checkbox選中的個(gè)數(shù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下2013-06-06淺談Jquery中Ajax異步請(qǐng)求中的async參數(shù)的作用
下面小編就為大家?guī)?lái)一篇淺談Jquery中Ajax異步請(qǐng)求中的async參數(shù)的作用。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06ligerUI的ligerDialog關(guān)閉刷新的方法
今天小編就為大家分享一篇ligerUI的ligerDialog關(guān)閉刷新的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09淺談window.onbeforeunload() 事件調(diào)用ajax
下面小編就為大家?guī)?lái)一篇淺談window.onbeforeunload() 事件調(diào)用ajax。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06jQuery實(shí)現(xiàn)條件搜索查詢、實(shí)時(shí)取值及升降序排序的方法分析
這篇文章主要介紹了jQuery實(shí)現(xiàn)條件搜索查詢、實(shí)時(shí)取值及升降序排序的方法,結(jié)合實(shí)例形式分析了jQuery針對(duì)頁(yè)面元素屬性操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-05-05jquery中的$(document).ready()使用小結(jié)
本篇文章主要是對(duì)jquery中的$(document).ready()使用方法進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02