function resize(){ var win_width=document.body.clientWidth; if(win_width<=1000){ $('.l').css('display','none'); }else{ var offset_width=(win_width-1000)/4;//对称 $('.l').css('display','block'); $(".l").css('width',offset_width); $('#l1').html('当前宽度为'+offset_width+"px"); } } <style type="text/css"> div {border:1px solid red;} #l2 {width:1000px;height:200px;margin:auto;} #l1 {left:0px;height:200px;} #l3 {right:0px;height:200px;} .l {position:fixed;width:100px;height:200px;top:0px;} </style><body onResize="resize()">
。
3.如何使用jq写javascript 代码
这样写没有任何作用,也没有返回值,也无法调取里面的东西。
下面这样就可以使用了。对于instance方法,估计作者在写方法的扩展吧。
var RES = {};(function (RES) {//。})(RES);//原来没有这个(RES),就是说原来只是个带参数的匿名函数,但是却没有执行//按上面的才有效,那么最后的RES.loadConfig 就可以调用了,//而url和resourceRoot只是两个参数而已,内部根据需求加以判断。
//也可以这样写:(function() { var RES = { loadConfig: function (url, resourceRoot) { if (typeof resourceRoot === "undefined") { resourceRoot = ""; } instance.loadConfig(url, resourceRoot); } } window.RES = RES;})();//或者:window.RES = { loadConfig: function (url, resourceRoot) { if (typeof resourceRoot === "undefined") { resourceRoot = ""; } instance.loadConfig(url, resourceRoot); }}//作用是一样的,调取方法:alert(typeof RES.loadConfig('/','/') );。