首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mootools切换div按钮上的css效果

问mootools切换div按钮上的css效果
EN

Stack Overflow用户
提问于 2016-02-26 12:55:25
回答 1查看 98关注 0票数 0

我有下面的脚本来显示/隐藏一些文本。我想让切换按钮成为一个当点击时会改变的图像。(例如,折叠时为"+ Title 1“,展开时为"- Title 1”)有什么方法可以做到这一点吗?

代码语言:javascript
复制
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:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2016-02-29 17:37:51

它可以是文本形式的(或者可以更改为CSS类)。这是一个有点笨拙的解决方案,但它是有效的。也许有人的反应更好。

代码语言:javascript
复制
$$('.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。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35643779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档