1

我希望我的徽标图像向上移动而不影响其下面的措辞,但是即使它们位于不同的 div 中,并且包含在父 div 中,也会触发这两个元素。我不明白。我假设它与边距有关,但是当我尝试为文本元素反向设置相反的值时,事情的表现很奇怪。

小提琴

CSS:

.full-circle {
display:block;
margin:auto;
margin-top: 15px;
overflow: hidden;
height: 180px;
width: 180px;
border: 2px solid #FFF;
-moz-border-radius: 90px;
-webkit-border-radius: 90px;
background:#FDF5E6;
-webkit-transition: margin 0.2s ease-out; 
-moz-transition: margin 0.2s ease-out; 
-o-transition: margin 0.2s ease-out;
}

.full-circle:hover{margin-top: 2px;}

jQuery:

$('.full-circle').hover(
            function(){
                $(this).stop().animate(
                    {marginTop: '2'}, 20, 'linear'   
                );//end animate
            },//end function
            function(){
                $(this).stop().animate(
                {marginTop: '15'}, 20, 'linear'
                );//end animate
            }//end function
        );//end hover
4

3 回答 3

1

您可以简单地添加position: relative.full-circle,然后为top属性设置动画,而不是margin-top.

$('.full-circle').hover(
    function(){
        $(this).stop().animate(
            {top: '-10'}, 20, 'linear'   
        );//end animate
    },//end function
function(){
    $(this).stop().animate(
        {top: '15'}, 20, 'linear'
        );//end animate
    }//end function
);//end hover

Working Demo

于 2013-04-08T05:57:38.853 回答
0

文本向上移动是因为两个项目都在流中,移动第一个会影响第二个的位置。

不要调整圆圈上的边距,而是应用position:relative;top 属性,然后将其调整为负值以将其向上移动top:-20px; (无论需要多少)。

调整相对定位元素的 top、bottom、left 或 right 属性会影响元素在屏幕上的绘制位置,而不会影响它与流中相邻元素的交互方式。

于 2013-04-08T05:39:57.660 回答
0

使用 CSS 很简单

.full-circle{margin-top:15px; margin-bottom:15px}

.full-circle:hover{margin-top:2px; margin-bottom:28px}

.logo{overflow:hidden;}

这将在没有 JQuery 的情况下完成,使用 jquery 也可以做到这一点,只需将更改应用于 margintop 和底部,这将管理更改。

现在您.grey的过滤器使它创建了额外的边距/填充,因此

我这样做是为了避免溢出的副作用.logo{ overflow:hidden}

工作小提琴

这会做。

于 2013-04-08T06:12:57.650 回答