虽然做mouseover时,做鼠标移动时做其他事情
问题描述:
我在另一个问题中看到了这段代码,我想我也可以使它成为一个图像的工作,但由于我是jquery的新手,我没有做太多。虽然做mouseover时,做鼠标移动时做其他事情
下面是代码:
$('someObject').bind('mouseover', function() {
//Do the following while mouseover
$('someOtherObject').css('margin-left',adjustedLeft + 'px');
setTimeout(/*do it again*/,25);
});
我看到它在这个问题就在这里: An "if mouseover" or a "do while mouseover" in JavaScript/jQuery
有它下面也是一个例子,但是这一个适用于文本字段。
我想我的,为图像的工作,基本上我有2个图像层叠而上,我想做出一个衰落的影响,所以像
鼠标悬停时,每0,01sec,由0.01降低不透明度,直到0,01, 鼠标离开图像(按钮)的那一刻,停止降低不透明度,并开始每0.01秒再次提高0.01,直到0.99不透明度
只是要再次清楚,我得到了2个图像(按钮) 1高于另一个,我想降低,然后提高上部按钮的不透明度。 另外我看到了另一种淡入淡出效果,但是2个按钮都在1张图片上,但是对于我来说(新手)我猜它太高级了,但我可能会看到它,这是我猜想使用较少图像的一种好方法。
以防万一,这里是链接到的例子太多:http://jsfiddle.net/YjC6y/29/
答
$('someObject').mouseover(function() {
$('someOtherObject').animate({
opacity: 0
})
}).mouseout(function() {
$('someOtherObject').animate({
opacity: 0.99
})
});
答
使用jQuery悬停http://api.jquery.com/hover/someObject
$('someObject').hover(
function() {
// Set the effect you want when mouse is over the element
},
function() {
// Set the effect for mouse leave
}
);
希望这有助于:)
这是最好$( )。有两个函数? – 2011-12-17 17:04:45
我真的不知道 – aWebDeveloper 2011-12-17 17:09:04
谢谢,这真的工作:),只是而不是“someOtherObject”我使用相同的,如果它的另一个对象,它没有正确动画 这是我使用的代码: $(LowerImage ).mouseover(函数(){ $(LowerImage).animate({ 不透明度:0 }) })鼠标移开(函数(){ $(LowerImage).animate({ 不透明度:0.99 })。 }); 还有一件事,我可以设置动画的速度吗?不要误解我的意思,速度是好的,我只是想知道如果我需要它在其他地方是不同的。 – Jordashiro 2011-12-18 11:35:42