我很好奇是否有办法衡量CSS3转换与基于javascript的动画(jQuery,Dojo)之间的CPU使用情况.当然,有一种优雅的解决方案可以跟踪这种情况下的资源使用情况.这是一个简单的例子:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#object1').hover(function(){
$(this).animate({marginLeft: '120px'}, 1000);
}, function(){
$(this).animate({marginLeft: '0px'}, 1000);
});
});
</script>
<style>
#object1 {
height: 400px;
width: 400px;
background: #4f9a23;
}
#object2 {
height: 400px;
width: 400px;
background: #343434;
-moz-transition: all 1s ease-in-out;
-webkit-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
#object2:hover {
margin-left: 120px;
}
</style>
</head>
<body>
<div id="object1"></div>
<div id="object2"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我很好奇某些宏正在做什么,并试图打电话(macroexpand-1)来获取更多信息.但是,我对如何扩展ClojureScript中的内置宏有点困惑,特别是cljs.core命名空间中的宏.根据文档,ClojureScript宏是用Clojure编写的,因此必须在Clojure REPL(而不是ClojureScript REPL)中进行测试,这是我一直在尝试的.
lein repl从我的ClojureScript项目目录运行,我试过这个:
=> (require 'cljs.compiler)
=> (require 'cljs.core)
=> (macroexpand-1 '(cljs.core/int 99.9))
(macroexpand-1 '(cljs.core/int 99.9))
(cljs.core/int 99.9)
Run Code Online (Sandbox Code Playgroud)
为什么会这样(cljs.core/int 99.9)?基于ClojureScript源代码,该宏不应该扩展到类似的东西(bit-or ~x 0)吗?
当我扩展非ClojureScript宏时,例如(macroexpand-1 '(when (even? 2) (println "2 is even"))),扩展似乎工作正常.
好像我在概念上遗漏了一些东西......