1、YUI使用的基本格式
<script> // Create a new YUI instance and populate it with the required modules. YUI().use('event', function (Y) { // Event is available and ready for use. Add implementation // code here. }); </script>
其中,'event'就是所谓的模块。并且函数中可以与多个模块并列,以便同时支持多重模块
2、YUI use函数中,如何在多个函数中传递信息。
实际上,use函数可以看作一个类,在第一次装载时可以创建各类变量以var申明。在多个函数或者事件函数中可以对这些变量进行引用
YUI().use('graphics', function (Y) { var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"}); var myrect = mygraphic.addShape({ type: "rect", stroke: { color:"#000", weight: 1 }, fill: { color: "#fde" }, width:40, height:50 }); var myellipse = mygraphic.addShape({ type: "ellipse", stroke: { color: "#ddd", weight: 2 }, fill: { color:"#f00", opacity: 0.5 }, width: 100, height: 30, x:100, y:50 }); var mycircle = mygraphic.addShape({ type: "circle", stroke: { color:"#ff0", weight: 1 }, fill: { color:"#00f" }, radius: 12, x: -5, y: -5 }); function rotateShapes(e) { myrect.rotate(45); myellipse.rotate(45); } function translateShapes(e) { mycircle.translate(50, 60); } Y.on("click", rotateShapes, "#rotate"); Y.on("click", translateShapes, "#translate"); });