【发布时间】:2017-05-16 12:20:08
【问题描述】:
当用户点击加载更多按钮并且卡片包装器具有类列表视图时。
我想获取 mason 样式 attr 值并在其上添加 300px 并将该值设置为 mason div。
这里的问题是我可以获得 mason arrt 值,但 newheight 返回“NaN”。
请帮忙!!
$('.load-more').on('click', function() {
if ($('.cards-wrapper').hasClass('list-view')) {
setTimeout(function() {
var currentHeight = $('.mason').attr('style');
console.log('current' + currentHeight);
var newHeight = parseInt(currentHeight);
console.log('new height' + newHeight);
$('.mason').css('height', newHeight + 300);
}, 3000);
}
});
<div class="mason clear-fix" style="height: 6380px;">
【问题讨论】:
-
你为什么要阅读风格???阅读高度! api.jquery.com/height 或 css("height")
-
currentHeight = $('.mason').attr('style') ??那不是高度
-
height 或 innerHeight 值与 mason 样式高度值不同,所以我需要获取 arrt 值
标签: javascript jquery