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ì)完整的顯示出來,控制段落來顯示文字,不需要的時(shí)候,可以再次點(diǎn)擊后將內(nèi)容折疊起來,也就是隱藏了一部分內(nèi)容。點(diǎn)擊查看更多的功能,在很多大網(wǎng)站都有在用,像一些電影簡介、產(chǎn)品介紹有時(shí)候?yàn)榱隧撁娴牟季中Ч?,常常默認(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)滑過由下向上展開效果示例【測試可用】
- jquery控制頁面的展開和隱藏實(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)的頁面詳情展開收起功能示例
相關(guān)文章
jquery 實(shí)現(xiàn)輪播圖詳解及實(shí)例代碼
這篇文章主要介紹了jquery 實(shí)現(xiàn)輪播圖相關(guān)資料,經(jīng)過一段時(shí)間學(xué)習(xí)jquery 的知識(shí),這里寫一個(gè)簡單的輪播圖,需要的朋友可以參考下2016-10-10
jQuery選擇器源碼解讀(八):addCombinator函數(shù)
這篇文章主要介紹了jQuery選擇器源碼解讀(八):addCombinator函數(shù),本文用詳細(xì)的注釋解讀了addCombinator函數(shù)的實(shí)現(xiàn)源碼,需要的朋友可以參考下2015-03-03
jQuery輕松實(shí)現(xiàn)表格的隔行變色和點(diǎn)擊行變色的實(shí)例代碼
下面小編就為大家?guī)硪黄猨Query輕松實(shí)現(xiàn)表格的隔行變色和點(diǎn)擊行變色的實(shí)例代碼。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考,一起跟隨小編過來看看吧2016-05-05
jquery和javascript中如何將一元素的內(nèi)容賦給另一元素
將一元素的內(nèi)容賦給另一元素,在某些情況下還是比較實(shí)用的,下面為大家講解下jquery和javascript中是如何實(shí)現(xiàn)的2014-01-01
jQuery實(shí)現(xiàn)對(duì)無序列表的排序功能(附demo源碼下載)
這篇文章主要介紹了jQuery實(shí)現(xiàn)對(duì)無序列表的排序功能,涉及jQuery與javascript常見的文本操作函數(shù)與sort排序函數(shù)的相關(guān)使用方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
JQuery 操作Javascript對(duì)象和數(shù)組的工具函數(shù)小結(jié)
JQuery提供了很多實(shí)用的工具函數(shù)。這些函數(shù)主要分為兩類,操作集合數(shù)組的函數(shù)和非集合數(shù)組函數(shù)。2010-01-01
解決jquery操作checkbox火狐下第二次無法勾選問題
在工作中使用jquery操作checkbox,進(jìn)行全選、反選,現(xiàn)在的問題是火狐下第二次無法勾選問題,在下面有個(gè)詳細(xì)的解答,感興趣的朋友可以參考下2014-02-02

