Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使jquery CSS操作同步(即没有回调)?_Javascript_Jquery_Css_Asynchronous_Callback - Fatal编程技术网

Javascript 如何使jquery CSS操作同步(即没有回调)?

Javascript 如何使jquery CSS操作同步(即没有回调)?,javascript,jquery,css,asynchronous,callback,Javascript,Jquery,Css,Asynchronous,Callback,所以基本上我有css,当元素悬停时,它会使元素变大(增加高度)。我希望能够有一个函数,允许您单击元素,禁用悬停功能(通过使用.css()将高度设置回其正常状态),触发不同的代码段,然后在完成后将悬停高度设置回正常状态。由于.css()没有回调功能,我有点困惑于如何实现这一点 这里有一个JSFIDLE,它给出了我想要做的事情的布局 下面是有问题的代码行 //this fires first, disabling the hover height of 200px; $(".single-item

所以基本上我有css,当元素悬停时,它会使元素变大(增加高度)。我希望能够有一个函数,允许您单击元素,禁用悬停功能(通过使用.css()将高度设置回其正常状态),触发不同的代码段,然后在完成后将悬停高度设置回正常状态。由于.css()没有回调功能,我有点困惑于如何实现这一点

这里有一个JSFIDLE,它给出了我想要做的事情的布局

下面是有问题的代码行

//this fires first, disabling the hover height of 200px;
$(".single-item:hover").css({"height":"100px"});

//the code I want to fire, fires second
$("#6").html("Hello");

//after the code finishes firing, put the hover height back to how it was    
$(".single-item:hover").css({"height":"200px"}); 

试试这个,我觉得它更接近你想要的,但可能不准确。如果这还不够好,您可能需要研究JavaScript回调

$(".single-item").on('click', function() {
    //this fires first, disabling the hover height of 200px;
    $(this).css("height", "100px");

    //the code I want to fire, fires second
    $("#6").html("Hello");
});

$(".single-item").on('mouseout', function() {
    $(this).css("height", "");
});

另外,使用所有jQuery事件比混合使用JavaScript和jQuery要容易得多。

等等,所以当有人悬停时,div会被扩展。然后出现“你好”。然后恢复div高度。都在同一个盘旋中?我不明白你想实现什么。“禁用悬停功能(使用.css()将高度设置回正常状态)”和“完成后将悬停高度设置回正常状态”是什么意思?也许这只是个例子,但为什么ID应该以字母开头。需要回调的不是
.css
,而是“触发不同的代码段”。这到底是什么?抱歉,这是我的错,但我的现实世界问题实际上使用了onclick事件的复选框(因此,不可能进行鼠标移出)。此外,css必须在主代码之前启动。我真正的问题是一个叫做同位素的插件。基本上,我是在动态地更改同位素的值,但当我这样做时,悬停css会弄乱站点布局。基本上,我正在尝试停止悬停,更新同位素,然后重置悬停,所有这些都是通过一个复选框onclick事件完成的。哦,哇,对不起,我刚刚意识到mouseout可以工作,因为悬停绑定到复选框的父元素。不过,初始css更改必须在主代码之前进行。