0

旧代码

当我在“#search” div 上方时遇到问题,然后它像我应该做的那样滑动它,但问题是当它滑出时它会显示一个搜索输入字段,当鼠标移过该输入字段时它开始运行鼠标移出功能,我已经通过在带有空函数的 #search 输入上提供 if 鼠标来停止此操作,但是当我的鼠标离开输入和“#search”潜水时,它不会运行动画返回功能。

这是我的脚本

$("#search").mouseover(function(){
    $(this).animate({"left": "0px"}, 500);
});
$("#search").mouseout(function(){
    if($("#search input").mouseover()){
        return false
        }
    else {
    $(this).animate({"left": "-282px"}, 500);
    }
});

我做错了什么?或者有人有解决方案吗?我是 jQuery 新手,所以刚开始学习 :) 并且我搜索了谷歌和过去 2 天的文档,也许只有我是盲人,这就是我需要你帮助的原因:

编辑:新代码和 JS 小提琴

我需要对搜索栏进行不同的处理,所以我只是再次编写了代码,现在需要单击该语句。看看这里 JSfiddle

http://jsfiddle.net/D7s45/2/

这就是我想要创建的 jQuery :)

4

2 回答 2

0

悬停输入时尝试停止传播:

$("#search input").hover(function(e) {
  e.stopPropagation();
}, function(e) {
  e.stopPropagation();
});

然后您的#search div 的常规代码应该可以正常运行。

于 2011-12-13T08:41:20.870 回答
0
var t, isout=true;
$("#search").children("form").children().mouseover(function () {
    clearTimeout(t); isout = false;
});

$("#search").children("form").children().mouseout(function () {
    isout = true;
    tout = setTimeout(function () { $("#search").animate({ "left": "-282px" }, 500); }, 100);

});

$("#search").mouseover(function () {
    if (isout) $(this).animate({ "left": "0px" }, 500);
    clearTimeout(t); isout = false;
});

$("#search").mouseout(function () {
    isout = true; tout = setTimeout(function () { $("#search").animate({ "left": "-282px" }, 500); }, 100);
});
于 2011-12-12T13:42:34.457 回答