它创建了一个断开连接具有属性的伪 jQuery 对象deg
set to 0
.
您以前可能见过这个:
var newDiv = $('<div>', {class: "hello"});
这创建了一个specific元素类型并为其设置初始属性。没有指定元素类型也是一样的。
Note:这种类型的对象对于插入 DOM 无效,但您可以对其应用许多有用的 jQuery 方法。
因此,您可以使用该对象中的信息来做一些很酷的事情,如下所示:http://jsfiddle.net/TrueBlueAussie/cfmzau1w/ http://jsfiddle.net/TrueBlueAussie/cfmzau1w/
// Create a pseudo jQuery object (not connected to a DOM element)
var po = $({
deg: 0
});
// This is just the target object we want to change
$elem = $('#result');
// Use animate on the object, to make use of the step callback
po.animate({
deg: 360
}, {
duration: 5000,
step: function (now) {
// Take the computed value and use it on a real element!
$elem.css({
transform: 'rotate(' + now + 'deg)'
});
}
});
参考文献不明显,但在此页面上http://api.jquery.com/jquery/#jQuery-object http://api.jquery.com/jquery/#jQuery-object它有一个jQuery(object)
方法说:
jQuery(对象)
对象类型:普通对象
包装在 jQuery 对象中的普通对象。
在你的例子中object
是你的匿名对象所以长手该示例的伪代码类似于:
var anonymousObj = {
deg: 0
};
var wrappedInAjQueryObject = jQuery(anonymousObj);
wrappedInAjQueryObject.animate(targetPropertiesAndValues, someSettingsAndCallbacksInAnObject);