【问题标题】:Modify height after dynamic create with each动态创建后修改高度
【发布时间】:2015-12-02 06:09:21
【问题描述】:

我在含有同位素的列中有流体成分:

<template name="iso">
     <div class="{{anchor}}">
           <img src="{{image}}"/>
    </div>
</template>

我填写了模板,当anchor = taller 时,我需要宽度= 25% 并且高度相同*2。正方形是 25% 和相同的高度,宽是 50% 和高度是 /2。

在js中:

template.iso.onRendered= function(){
  $('.square').heigth() = $('.square').width 
  $('.toller').heigth() = $('.square').width * 2
  $('.widen').heigth() = $('.square').width 
};

但是,onRendered 在{{#each}} 的渲染之前运行,我拥有所有的 div,但高度没有改变。

有什么解决办法吗? (对不起我的英文写得不好)

【问题讨论】:

  • 可能只是拼写错误;你有“heigth”,应该是“height” 是的,英语是一种疯狂的语言,但是这个词发音为“hite”。
  • 首先你写了$('.square').heigth() ..更正它为$('.square').height()
  • 你好希望能帮到你,你试试添加CSS,例如:.square { height: auto; } 并且永远改变内容,这个调整

标签: jquery meteor jquery-isotope


【解决方案1】:

我解决了这个问题

Template.home.rendered = function() {
    if (!this.rendered){
        //the data is there but dom may not be created yet
                //$("img").unveil();
                var altoBase =  $('.isotope').width() / 5;
                var altoDoble =  altoBase * 2 ;

                $(  ".carta").each(function( i ) {
                    if ($( this).hasClass('alto') ) {
                        $( this ).css({
                            height: altoDoble + 'px',
                            backgroundColor: "green"
                        });
                    } else {
                        $( this ).css({
                            height: altoBase + 'px',
                            backgroundColor: "white"
                        });
                    }
                });
                var self = this;
                self.selection = this.$('.isotope').isotope({
                    itemSelector: '.carta',
                    masonry: {
                        gutter: 0
                    }
                });
    }

};

这个解决方案也适用于同位素

【讨论】:

    猜你喜欢
    • 2013-06-15
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    相关资源
    最近更新 更多