我有下面的脚本来显示/隐藏一些文本。我想让切换按钮成为一个当点击时会改变的图像。(例如,折叠时为"+ Title 1“,展开时为"- Title 1”)有什么方法可以做到这一点吗?
window.addEvent( 'domready', function(){
$$( '.moreInfoWrapper' ).each(function(item){
var thisSlider = new Fx.Slide( item.getElement( '.moreInfo' ), { duration: 500 } );
thisSlider.hide();
item.getElement( '.divToggle' ).addEvent( 'click', function(){ thisSlider.toggle(); } );
} );
} );Html:
<div class='moreInfoWrapper'>
<div class='divToggle'>
<h3>Title 1</h3>
</div>
<div class='moreInfo'>
<h3>More Info About Item 1</h3>
<p>Here is some content.</p>
<p>More Content</p>
<p>End of Content</p>
</div>
</div>
<div class='moreInfoWrapper'>
<div class='divToggle'>
<h3>Title 2</h3>
</div>
<div class='moreInfo'>
<h3>More Info About Item 2</h3>
<p>Here is some content.</p>
<p>More Content</p>
<p>End of Content</p>
</div>
</div>发布于 2016-02-29 17:37:51
它可以是文本形式的(或者可以更改为CSS类)。这是一个有点笨拙的解决方案,但它是有效的。也许有人的反应更好。
$$('.moreInfoWrapper .moreInfo').each(function(item){
item.set('slide', { duration: 500 }).slide('hide');
});
$$('.moreInfoWrapper .divToggle').each(function(item){
item.addEvent('click', function(e){
var el = this.getFirst('h3');
if (this.getNext('div').getDimensions().height == 0) {
el.set('html', el.get('html').replace('+','-'));
} else {
el.set('html', el.get('html').replace('-','+'));
}
this.getNext('div').getFirst('.moreInfo').slide('toggle');
});
});Ty it on this jsfiddle。
https://stackoverflow.com/questions/35643779
复制相似问题