我正在尝试使多边形与同级div动画。我认为由于处于绝对位置而没有进行动画处理?有没有办法让它与同胞div一起滑动?
这是一个小提琴:http://jsfiddle.net/Lzxmk5jp/2/
jQuery的:
$('.one').on('click',function(){
var width = $('.one').width(),
parentWidth = $('.one').offsetParent().width(),
percent = 100*width/parentWidth;
if(percent < '34'){
$('.one').animate({
width:'66%'
}, 1000),
$('.one .svg-right-arrow').animate({
left:'100%'
}, 1000)
}
if(percent > '34'){
$('.one').animate({
width:'34%'
}, 1000),
$('.one .svg-right-arrow').animate({
left:'100%'
}, 1000)
}
});
的HTML:
<div class="cont">
<div class="one">
<div class="one-inner"></div>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-right-arrow" viewBox="0 0 20 152" preserveAspectRatio="xMinYMid meet">
<polygon points="0,0 0,152 20,76"></polygon>
</svg>
</div>
</div>
最佳答案
这与它们一起移动无关,箭头位于框的外部,当您使用.animate()
时,它会隐藏过渡期间的溢出内容。您可以使.one-inner
背景色的宽度减小,并在框内保留箭头以使其一起移动(注意,您必须使用空格来使它看起来更好,我的是一个简单的示例来解释这种行为) :
.one-inner{
background-color:#ed7581;
width:75%;
height:370px;
}
.one .svg-right-arrow{
position: absolute;
left: 74%;
top:0;
z-index: 10;
height:100%;
}
FIDDLE