【发布时间】:2016-01-28 17:46:03
【问题描述】:
我试图让一些 div 对我的 mouseOver 和 mouseOut 做出反应。我正在尝试构建类似于 Vimeo 风格的音量栏的东西。
我正在让条形图对 mouseOver 做出反应,但我希望它们在 mouseOut 之后返回到原来的高度。每个条的高度不同。当它被硬编码时它可以工作,但我试图使用尽可能少的代码。
这是我的 JQuery:
$(document).ready(function() {
var totalHeight = '100%';
var initHeight;
function getHeight(h) {
initHeight = h;
//alert(initHeight);
}
$("div#barWrap").children().mouseover(function() {
// This is where I am having trouble. I want to get the original height of the bar so I can reuse it on mouseOut
getHeight($("div#barWrap").children().css('height'));
// Animate bar
$(this).animate({ height: totalHeight}, 100);
});
$("div#barWrap").children().mouseout(function() {
$(this).animate({ height: initHeight}, 400);
});
});
任何帮助将不胜感激。
【问题讨论】: