博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
dojo自定义widget
阅读量:5954 次
发布时间:2019-06-19

本文共 2785 字,大约阅读时间需要 9 分钟。

hot3.png

http://dojotoolkit.org/documentation/tutorials/1.8/recipes/custom_widget/

目录结构:

最终效果:

关键代码:

index.htm

Insert title here

AuthorWidget.html

${name}

${!bio}

AuthorWidget.js

//custom/AuthorWidget.jsdefine(["dojo/_base/declare","dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!./AuthorWidget/templates/AuthorWidget.html", "dojo/dom-style", "dojo/_base/fx", "dojo/_base/lang","dojo/on"],    function(declare, WidgetBase, TemplatedMixin, template, domStyle, baseFx, lang, on){        return declare([WidgetBase, TemplatedMixin], {			name: "No Name",			avatar: require.toUrl("custom/AuthorWidget/images/defaultAvatar.gif"),			bio: "",						templateString: template,			baseClass: "authorWidget",			mouseAnim: null,						baseBackgroundColor: "#fff",			mouseBackgroundColor: "#def",						postCreate: function(){			    // Get a DOM node reference for the root of our widget			    try{				    var domNode = this.domNode;				 					    // Run any parent postCreate processes - can be done at any point				    this.inherited(arguments);				 				    domStyle.set(domNode, "backgroundColor", this.baseBackgroundColor);				    				    //way #1				    var that = this;				    on(domNode, "mouseenter", function (e) {				    	//console.log(this===domNode); //true				    	//console.log(that); //widget				        that._changeBackground(that.mouseBackgroundColor);				    });				    				    //way#2				    on(domNode, "mouseleave", lang.hitch(this, function (e) {				    	//console.log(this===domNode); //false				        this._changeBackground(this.baseBackgroundColor);				    }));				    			    }catch(e){			    	console.log("error:",e);			    }			},						_changeBackground: function(toCol) {			    // If we have an animation, stop it			    if (this.mouseAnim) { this.mouseAnim.stop(); }			 			    // Set up the new animation			    this.mouseAnim = baseFx.animateProperty({			        node: this.domNode,			        properties: {			            backgroundColor: toCol			        },			        onEnd: lang.hitch(this, function() {			            // Clean up our mouseAnim property			            this.mouseAnim = null;			        })			    }).play();			},			_setAvatarAttr: function(av){				if(av != ""){					this._set("avatar",av);					this.avatarNode.src = av;				}			}		});	});

authors.json

[    {        "name": "Kitten",        "avatar": "includes/authors/kitten.jpg",        "bio": "Brian Arnold is a software engineer at SitePen, Inc., ..."    },    {        "name": "Cyper",        "avatar": "includes/authors/cyper.jpg",        "bio": "Cyper is a software engineer at SitePen, Inc., ..."    },    {        "name": "sb",        "avatar": "includes/authors/sb.gif",        "bio": "sb is b, ..."    }]

转载于:https://my.oschina.net/uniquejava/blog/113066

你可能感兴趣的文章
我的友情链接
查看>>
golang xml和json的解析与生成
查看>>
javascript 操作DOM元素样式
查看>>
Android 内存管理 &Memory Leak & OOM 分析
查看>>
【查找算法】基于存储的查找算法(哈希查找)
查看>>
JavaWeb网上图书商城完整项目--day02-10.提交注册表单功能之页面实现
查看>>
记录一下这次web实训的两个网站
查看>>
POJ-1830 开关问题 高斯消元
查看>>
做程序开发的你如果经常用Redis,这些问题肯定会遇到
查看>>
CAS-认证流程
查看>>
006android初级篇之jni数据类型映射
查看>>
Java 集合框架查阅技巧
查看>>
apache配置虚拟主机
查看>>
CollectionView水平和竖直瀑布流的实现
查看>>
前端知识复习一(css)
查看>>
spark集群启动步骤及web ui查看
查看>>
利用WCF改进文件流传输的三种方式
查看>>
Spring学习总结(2)——Spring的常用注解
查看>>
关于IT行业人员吃的都是青春饭?[透彻讲解]
查看>>
钱到用时方恨少(随记)
查看>>