背景位置和前置正常工作正常,但懸停在元素上的寬度沒有接收到下面例程的新寬度。我想我已經嘗試了所有的語法排列,除了正確的排列!除非因爲任何原因,李的寬度不能以這種方式改變?爲什麼在這個片段中懸停狀態的寬度沒有改變
我甚至試着用css('width','128)設置css,那樣做不行......用動畫思考的東西引起了一個問題..但我很難過。
$(document).ready(function() {
initwidth = $("li").width(); // updated
// hover in
$(".qnav li").hover(
function(){
// start the animation
$(this).stop().animate({width: "128"},{queue:false, duration:"fast" });
$(this).stop().animate({backgroundPosition: "0 -30px"},{queue:false, duration:"fast" });
$(this).prepend('<span class="prepended">Question </span');
// hover out
},function(){
$(this).stop().animate({width: initwidth});
$(this).stop().animate({backgroundPosition: "0 0"},{queue:false, duration:"fast" });
$(".prepended").remove();
}
);
});
在元件上的CSS是:
.qnav li{
display: block;
float: left;
height: 30px;
line-height: 2;
width:38px;
padding: 0;
background:#aaa9a9 url(images/arrowSprite.png) no-repeat 0 0;
}
不是答案,但請更改initwidth = $(「li」)。 to var initwidth = $(「li」)。width(); – 2012-04-22 16:34:45
不確定是否需要,但您是否嘗試添加「px」?像:'width:「128px」'。 – powerbuoy 2012-04-22 16:34:52
請打開jsfiddle或jsbin – 2012-04-22 16:43:27