【发布时间】:2016-11-09 23:58:45
【问题描述】:
我刚开始做一些 jquery 和 sass,所以我有点困惑。 我的问题是我可以像这样使用 mixin:
@mixin borderradius {
border-top-left-radius : 100;
border-top-right-radius : 100;
border-bottom-right-radius : 100;
border-bottom-left-radius : 100;
}
在 jquery 代码中是这样的:
$(document).ready(function() {
$('#divic,#divonja').mouseenter(function() {
$(this).animate({
borderTopLeftRadius: 100,
borderTopRightRadius: 100,
borderBottomLeftRadius: 100,
borderBottomRightRadius: 100
}, 200);
});
$('#divic,#divonja').mouseleave(function() {
$(this).animate({
borderTopLeftRadius: 0,
borderTopRightRadius: 0,
borderBottomLeftRadius: 0,
borderBottomRightRadius: 0
}, 200);
});
$('#divic,#divonja').click(function() {
$(this).toggle(1000);
});
});
我可以写@include borderradius之类的东西,而不是写所有这些边界半径4次? 像这样的:
$(document).ready(function() {
$('#divic,#divonja').mouseenter(function() {
$(this).animate({
@include borderradius
}, 200);
});
$('#divic,#divonja').mouseleave(function() {
$(this).animate({
@include borderradius
}, 200);
});
$('#divic,#divonja').click(function() {
$(this).toggle(1000);
});
});
【问题讨论】:
-
如果四个值都相同,为什么不使用
.animate( { borderRadius: 0 } )? -
你可以!这叫变量!只需引用动画配置对象并将它们放在您通常编写对象的位置...
-
我尝试使用borderRadius:0,但是在mouseenter上它的动画效果非常好,但在mouseleave上它的速度非常快,正如我所说我只是这一切的初学者:D!非常感谢:)!
标签: javascript jquery html css sass