如何使jquery的CSS操作同步(即没有回调)
How to make jquery CSS manipulation synchronous (i.e. without callbacks)?
所以基本上我有css使元素在悬停时变大(增加高度)。我希望能够有一个功能,允许您单击元素,禁用悬停功能(通过设置高度回到它的正常状态与。css()),触发不同的代码段,然后设置悬停高度回到正常时完成。由于。css()没有回调功能,我有点困惑如何做到这一点。
这是一个jsfiddle,它给出了我想要做的布局。
http://jsfiddle.net/lennox02/99KB2/3/有问题的代码行
//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"});
试试这个,我认为它更接近你想要的http://jsfiddle.net/99KB2/6/但可能不准确。如果这还不够好,你可能不得不考虑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容易得多。
相关文章:
- 如何制作add的回调函数或同步制作此脚本
- 同步 jQuery 调用,无需将所有内容放入回调中
- 在 Angular JS 中同步回调
- Node.js for 循环,带有回调,之后同步执行
- 同步窗口.设置超时回调
- 将函数的执行同步为 node.js 中的回调参数
- ExtJS 6 访问消息属性在存储同步的回调
- 在自定义的 for-each 循环中链接回调,同时支持同步和异步函数
- 从回调填充本地数组:同步问题
- Clojuescrapt ajax.core没有单独的处理程序/回调,代码中的流非常精确,就好像代码是同步的一样
- 如何识别回调是同步执行还是异步执行
- 函数内的两个回调函数未同步调用
- 并发AJAX回调:如何同步它们
- 在同步上下文中调用defer.notify()不会执行回调
- 对象.观察同步回调
- javascript中异步回调的结构:同步异步
- 如何使jquery的CSS操作同步(即没有回调)
- Node.js -承诺和回调Vs同步
- Javascript同步;没有回调
- 在AngularJS中,模型和视图在回调后不同步,并且$apply给出错误