gpt4 book ai didi

jquery - 动态创建后修改高度

转载 作者:行者123 更新时间:2023-12-01 05:37:39 25 4
gpt4 key购买 nike

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

<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,但高度没有改变。

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

最佳答案

我解决这个问题

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
}
});
}

};

该解决方案也适用于同位素

关于jquery - 动态创建后修改高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32907362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com