/** * Created by Dongdong on 2015/4/28.*/(function($){ varDefaults ={height:40,//height after text is closedSpeed: ' Normal ',//speed of text unwinding and unwindingdown:{"class": "Fold-down", "Text": "Expand"},//Expanded Stylesup:{"class": "Fold-up", "text": "Close"}//style of the collection }; $.fn.accordiontext=function(options) {Options=$.extend (defaults,options); return This. each (function(){ varc = $ ( This), H=c.height (), Ph= parseint (C.css ("Padding-top"). Replace ("px", "")) +parseint (C.css ("Padding-bottom"). Replace ("px", "" ")), T= $("#"+$( This). Data (' Switch ')); C.css ({overflow:"Hidden", height:options.height + ph + "px"}); T.toggle (function(){ $( This). Text (Options.up.text). Removeclass (Options.down.class). addclass (Options.up.class); C.animate ({height:h+ph + "px"},options.speed); }, function(){ $( This). Text (Options.down.text). Removeclass (Options.up.class). addclass (Options.down.class); C.animate ({height:options.height+ph + "px"},options.speed); }). Text (Options.down.text). addclass (Options.down.class); }); }}) (JQuery);
Call (the bootstrap icon style is used here):
$ (function() { $ (". Text"). Accordiontext ({ down:{"class": "Glyphicon Glyphicon-chevron-down "," Text ":" "}, up:{" class ":" Glyphicon glyphicon-chevron-up "," Text ":" "} }) ; });
Html:
<styletype= "Text/css">. Switch{text-align:Center;cursor:Pointer;Height:20px;Line-height:20px;}. Text{padding:3px;} </style><Div> <Divclass= "Text bg-success"Data-switch= "BTN2">Soda Green on the plane to see the place is the leader saw Phillips weight loss intersection to pay the electricity and power junction is junction with Soda Green on the plane to see the place is the leader saw Phillips weight loss intersection to pay the electricity bill Junction is junction with Soda Green fly on the plane to see the place is the leader see Felix Minus Fat Junction intersection is junction with Soda Green on the plane to see the place is the leader saw Phillips weight loss intersection intersection is the intersection is considering the liberation of the road to go to sleep crazy fast Christmas intersection four quarter Phillips jiangdong elders acceptable kai-Fu Lee is the departure of the plane lost link fast decline Fat Soracá Click the law exam Big Brother-in-iaw drool of weight loss two mobile phone to kill two mobile phone fee intersection sleeping Frank pay the water and electricity intersection is to leave the plane to see click</Div> <Divclass= "Switch"><spanID= "BTN2"></span></Div></Div>
Download
jquery Text Folding