我认为问这个问题的最好方法是只显示代码:
var counter = 1;
$('#animation').click(function () {
if (!$('h2').is(':animated')) {
if (counter == 5) {
toTheRight = !toTheRight;
counter = 0;
}
var movement = (.2 * $('h2').width()) + "px";
if (toTheRight) {
$('h2').animate({
"font-size": "2.2em",
"width": "50%",
"left": "+=" + movement
}, { queue: false, duration: 1000 });
}
else {
$('h2').animate({
"font-size": "2.2em",
"width": "50%",
"left": "-=" + movement
}, { queue: false, duration: 1000 });
}
counter++;
}
});
此功能非常适用于从头到尾保持相同大小的窗口。我想知道是否有一种优雅的方式来处理窗口调整大小,而不仅仅是将元素的当前位置一直重置到左侧。
注意:如果在全屏模式下并且元素一直向右,则缩小屏幕而不调整元素位置会导致元素滚动到屏幕右侧。
感谢您提供的任何建议。