在遇到jquery插件的麻烦之后,我决定自己开发一个类似的脚本。(这也是一种很好的做法)。总之,我编写了两个基于动画()函数的jquery函数。
minimizeBubble
将气泡返回到其默认大小
maximizeBubble
使气泡更大、更高,并显示另一张图片(这个气泡的标题)
jQuery.fn.maximizeBubble = function(){
$(this).animate({
marginTop: '-300px',
width: '300px',
}, {
duration: 200,
specialEasing: {
width: 'linear',
},
complete: function() {
$(this).find("span").css("display" , "inline");
}
});
}
jQuery.fn.minimizeBubble = function(){
$(this).animate({
//top: '+=5',
marginTop: '0',
width: '80px',
}, {
duration: 100,
specialEasing: {
width: 'linear',
},
complete: function() {
$(this).find("span").css("display" , "none");
}
});
}我还编写了下一个代码:我知道在本例中,.each()函数不是苗圃函数,因为一次只有一个大气泡。
$(document).ready(function() {
//First , the middle one will be big as default.
$('#auto_big').maximizeBubble();
//mouseOver - make it big , onMouseout - Stay Big (do nothing)
$('.dock-item2').mouseover(function() {
//mouseOver on another bubble- minimize the other one and maximize the current
$('.dock-item2').each(function(){
$(this).minimizeBubble();
});
$(this).maximizeBubble();
});
});(用于我的代码的jsFiffle:http://jsfiddle.net/T7gCL/1/)
问题是,正如你可以看到的:当你移动鼠标进入下一个泡泡时,所有的气泡都开始“疯狂”了。
1.你知道这种行为的原因吗?
2.如何解决这一问题?
3.对于如何改进我的代码(例如:代替each()),您有什么建议吗?
发布于 2012-03-06 21:22:17
有这么多跳来跳去的部分原因是你绝对地定位了图像,然后调整它们的大小。我不知道应用程序需要什么,但我现在会尝试浮动它们。动画行为就像一种连锁反应,使我得出这样的假设:当图像调整大小时,它将onMouseover事件传播到重叠的图像上。浮动布局可以解决这个问题。
更新
这样做更好,但可能不是你想要做的
$('.dock-item2').mouseenter(function(event) {
event.stopPropagation()
$(this).maximizeBubble();
});
$('.dock-item2').mouseleave(function(event) {
event.stopPropagation()
$(this).minimizeBubble();
});您仍然需要重新处理在包含div的图像中组织图像的方式
https://stackoverflow.com/questions/9591233
复制相似问题