【发布时间】:2015-03-23 18:32:36
【问题描述】:
$( "#transbox1" ).one( "mouseenter", function() {
$( this ).css( "width", "+=200" );
$( this ).css( "height", "+=200" );
});
$( "#transbox1" ).one( "mouseleave", function() {
$( this ).css( "width", "-=200" );
$( this ).css( "height", "-=200" );
});
$( "#transbox2" ).one( "mouseenter", function() {
$( this ).css( "width", "+=200" );
$( this ).css( "height", "+=200" );
});
$( "#transbox2" ).one( "mouseleave", function() {
$( this ).css( "width", "-=200" );
$( this ).css( "height", "-=200" );
});
$( "#transbox3" ).one( "mouseenter", function() {
$( this ).css( "width", "+=200" );
$( this ).css( "height", "+=200" );
});
$( "#transbox3" ).one( "mouseleave", function() {
$( this ).css( "width", "-=200" );
$( this ).css( "height", "-=200" );
});
$( "#transbox4" ).one( "mouseenter", function() {
$( this ).css( "width", "+=200" );
$( this ).css( "height", "+=200" );
});
$( "#transbox4" ).one( "mouseleave", function() {
$( this ).css( "width", "-=200" );
$( this ).css( "height", "-=200" );
});
我有 4 个盒子,使用 mouseenter,盒子会变大 200px,当鼠标离开时,盒子会变小 200px。我怎么能一直这样做?
【问题讨论】:
-
你可以使用相同的类,不需要循环
-
现在您使用的是
.one()- 事件调用一次然后分离 - 还是.on()?
标签: javascript jquery html loops