【发布时间】:2013-11-26 20:13:09
【问题描述】:
我一直在寻找,但没有找到任何东西。我需要在一个 100% 宽度的容器内放置一堆 100% 宽度的子元素。
每个子元素的定位需要比前一个子元素多 100% 的 margin-left。 基本上模拟如果他们只是用左浮动定位它们会如何
这是告诉第一个孩子之后的所有孩子都向右移动 100%
$('.responsiveSlider').find('.responsiveSliderSlide').each(function() {
$(this).next().css('margin-left', +100+'%');
});
现在我得到 孩子 1 左边距 0 child 1 margin-left 100% child 1 margin-left 100% child 1 margin-left 100%
努力实现: 孩子 1 左边距 0 child 1 margin-left 100% child 1 margin-left 200% child 1 margin-left 300%
---解决方案---
var thisSlideWidth = 1;
$('.responsiveSlider').find('.responsiveSliderSlide').each(function() {
//var thisSlideWidth = $(this).width();
var nextSlideLocation = thisSlideWidth + '00%';
$(this).next().css('margin-left', nextSlideLocation);
thisSlideWidth++;
});
【问题讨论】:
-
没关系,想通了...用解决方案更新了原始帖子
标签: javascript jquery