posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          create div

          Posted on 2008-09-15 01:02 G_G 閱讀(436) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): javascript
          直接 運(yùn)行 div_show_drag.rar
          http://www.aygfsteel.com/Files/Good-Game/div_Show_drag.rar

          html test
          <html>
          <head>

          <script?type="text/javascript"?src="showDivUtil.js"></script>

          </head>

          <body>

          <input?type="button"?id="_in"?value="google-baidu"?onclick="test();"/>
          <div?id='_div'?/>
          <script?language="javascript">
          /*api說(shuō)明
          ????ShowDiv(?源element?,?是否使用現(xiàn)有?div?)
          ????????源element,是否使用現(xiàn)有?div?都可為null?;
          */
          var?ediv?=?new?ShowDiv('_in',null);

          function?test(){
          ????
          if(?!?ediv.isShow?){
          ????????
          // tdiv[X,Y,H,W]準(zhǔn)備展現(xiàn)div set->tdiv.X = ..? ? ,
          ??????? // tsubEle[X,Y,H,W]
          ??????? // 源ele大小位置??,tscreen[
          screenH,screenW]屏幕長(zhǎng)寬
          ????????ediv.setLocation?=?function(tdiv,tsubEle,tscreen){
          ????????????
          /*??居中展現(xiàn)
          ?????????????tdiv.W?=200?;
          ?????????????tdiv.H?=?300?;
          ?????????????tdiv.X?=?tscreen.screenW/2-tdiv.W/2?;
          ?????????????tdiv.Y?=?tscreen.screenH/2-tdiv.H/2?;
          ????????????
          */

          ?????????????
          /*??根據(jù)?tsubEle?位置?左顯示
          ????????????tdiv.X?=?tsubEle.X+tsubEle.W?;
          ????????????tdiv.Y?=?tsubEle.Y?;
          ?????????????
          */

          ??????????????
          /*??根據(jù)?tsubEle?大小??左長(zhǎng)條?顯示?
          ?????????????tdiv.X?=?tsubEle.X+tsubEle.W?;
          ?????????????tdiv.Y?=?tsubEle.Y?;
          ?????????????
          */
          ????????????
          ????????
          ??????????????
          /*??根據(jù)?tsubEle?大小??下長(zhǎng)條?顯示
          ?????????????tdiv.X?=?tsubEle.X+tsubEle.W?;
          ?????????????tdiv.Y?=?tsubEle.Y?;
          ?????????????tdiv.H?=?200?;
          ?????????????tdiv.W?=?tsubEle.W?;
          ?????????????
          */
          ????????????
          ????????????
          /*??..?等等?自己嘗試吧*/
          ????????????tdiv.innerHTML?
          =?"<li>google</li><li>baidu</li>"?;
          ????????????
          //可以參考?
          ????????????Drag.init(tdiv);
          ????????}????
          ????????ediv.setStyle('background
          -color:#F4F4F4;');
          ????????ediv.show();
          ????}
          else{
          ????????ediv.close();
          ????????
          //ediv.delete();
          ????}
          }

          </script>
          </body>
          </html>



          showDivUtil.js

          /*
          * Skynet
          *? 2008-9-15 00:56
          *?? liukaiyi@gmail.com
          */

          function?ShowDiv(subEle,ediv){
          ????
          //public?
          ????this.style??;
          ????
          this.isShow?=?false?;

          ????
          //private?
          ????this._div??;
          ????
          this._subEle??;
          ????
          this._subEle??;


          ????????
          if(?typeof?ediv?==?"undefined"?||?ediv?==?null)?
          ????????????
          this._div=document.createElement("div");
          ????????
          else?if(?typeof?ediv?==?"string")?
          ????????????
          this._div=document.getElementById(ediv);????
          ????????
          else?if(??/object/.test(typeof?ediv)?)
          ????????????
          this._div=?ediv?;
          ????????
          ????????
          if(?typeof?subEle?==?"string")?
          ????????????
          this._subEle=document.getElementById(subEle);????
          ????????
          else?if(??/object/.test(typeof?subEle)?)
          ????????????
          this._subEle=?subEle?;

          }

          ????
          //外置方法?x?,?y?,w?,?h?,?div
          ????ShowDiv.prototype.setLocation?=?new?Function()?;

          ????
          //設(shè)置?div?樣式
          ????ShowDiv.prototype.setStyle=function(styleStrOrObj){
          ????????
          this.style=this._div.style?;
          ????????
          if(?typeof?styleStrOrObj?==?"string"){
          ????????????
          var?strs?=?styleStrOrObj.split(/;/)?;
          ????????????
          for(var?i=0;i<strs.length;i++){
          ????????????????
          var?key?=?strs[i].split(/:/)[0];
          ????????????????
          var?value?=?strs[i].split(/:/)[1];
          ????????????????
          var?_s?=?key.indexOf("-")?;
          ????????????????
          if(?_s>0)?
          ????????????????????key
          =key.substring(0,_s)+key.substring(_s+1,_s+2).toLocaleUpperCase()+key.substring(_s+2,key.length);
          ????????????????
          if(?key!=null&&key!=''&&key!='?'?){
          ????????????????????eval(?'
          this._div.style.'+key+'="'+value+'"'?);
          ????????????????}
          ????????????}
          ????????}
          else?if(??/object/.test(typeof?styleStrOrObj)?)?{
          ????????????
          this._div.style?=?styleStrOrObj?;
          ????????}
          ????????
          if(this._div.style.position==null?||?this._div.style.position=="")
          ????????????
          this._div.style.position="absolute";
          ????}
          ????
          ????ShowDiv.prototype.show
          =function(){
          ????????
          if(?typeof?this._subEle?!=?"undefined"?||?this._subEle?!=?null){
          ????????????
          this._subEle.Y?=?getElementPos(this._subEle).y;
          ????????????
          this._subEle.X?=?getElementPos(this._subEle).x?;
          ????????????
          this._subEle.W?=?this._subEle.offsetWidth?;
          ????????????
          this._subEle.H?=?this._subEle.offsetHeight?;
          ????????}
          ????????
          //this._div.Y?=?sset
          ????????//this._div.X?=?sset
          ????????this._div.W?=?parseInt(?this._div.style.width?);
          ????????
          this._div.H?=?parseInt(?this._div.style.height?);
          ????????
          ????????
          this.setLocation(this._div,this._subEle,{screenW:document.body.clientWidth,screenH:document.body.clientHeight});
          ????????
          this._div.style.left?=?this._div.X??;
          ????????
          this._div.style.top?=?this._div.Y?;
          ????????
          ????????
          if(?this._div.W?&&?this._div.H?){
          ????????????
          this._div.style.width?=?this._div.W?;
          ????????????
          this._div.style.height?=?this._div.H?;
          ????????}
          ????????document.body.appendChild(
          this._div);
          ????????
          this.isShow?=?true?;
          ????}

          ????ShowDiv.prototype.close
          =function(){
          ????????document.body.removeChild(
          this._div);?
          ????????
          this.isShow?=?false?;
          ????}

          ?????ShowDiv.prototype.
          delete=function(){
          ????????document.body.removeChild(
          this._div);?
          ????????
          this._div?=?null?;
          ????????
          this.isShow?=?false?;
          ????}

          ?
          //得到 Element 位置
          //?說(shuō)明:用?Javascript?獲取指定頁(yè)面元素的位置
          //
          ?整理:http://www.codebit.cn
          //
          ?來(lái)源:YUI?DOM
          function?getElementPos(el)?{
          ????
          var?ua?=?navigator.userAgent.toLowerCase();
          ????
          var?isOpera?=?(ua.indexOf('opera')?!=?-1);
          ????
          var?isIE?=?(ua.indexOf('msie')?!=?-1?&&?!isOpera);?//?not?opera?spoof
          ????if(el.parentNode?===?null?||?el.style.display?==?'none'){
          ????????
          return?false;
          ????}
          ????
          var?parent?=?null;
          ????
          var?pos?=?[];
          ????
          var?box;

          ????
          if(el.getBoundingClientRect){
          ????
          //?IE?
          ????????box?=?el.getBoundingClientRect();
          ????????
          var?scrollTop?=?Math.max(document.documentElement.scrollTop,?document.body.scrollTop);
          ????????
          var?scrollLeft?=?Math.max(document.documentElement.scrollLeft,?document.body.scrollLeft);
          ????????
          return?{x:box.left?+?scrollLeft,?y:box.top?+?scrollTop};
          ????}
          else?if(document.getBoxObjectFor){
          ?????
          //?gecko
          ????????box?=?document.getBoxObjectFor(el);
          ????????
          var?borderLeft?=?(el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;
          ????????
          var?borderTop?=?(el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;
          ????????pos?
          =?[box.x?-?borderLeft,?box.y?-?borderTop];
          ????}
          else?{
          ?????
          //?safari?&?opera
          ????????pos?=?[el.offsetLeft,?el.offsetTop];
          ????????parent?
          =?el.offsetParent;
          ????????
          if?(parent?!=?el)?{
          ????????????
          while?(parent)?{
          ????????????????pos[
          0]?+=?parent.offsetLeft;
          ????????????????pos[
          1]?+=?parent.offsetTop;
          ????????????????parent?
          =?parent.offsetParent;
          ????????????}
          ????????}
          ?????????
          if?(ua.indexOf('opera')?!=?-1||?(?ua.indexOf('safari')?!=?-1?&&?el.style.position?==?'absolute'?)){
          ????????????pos[
          0]?-=?document.body.offsetLeft;
          ????????????pos[
          1]?-=?document.body.offsetTop;
          ????????}
          ????}
          ?
          ????
          if?(el.parentNode)?{?parent?=?el.parentNode;?}
          ????
          else?{?parent?=?null;?}
          ?
          ?
          ????
          //?account?for?any?scrolled?ancestors
          ?????while?(parent?&&?parent.tagName?!=?'BODY'?&&?parent.tagName?!=?'HTML'){?????
          ????????pos[
          0]?-=?parent.scrollLeft;
          ????????pos[
          1]?-=?parent.scrollTop;
          ????????
          if?(parent.parentNode)?{?parent?=?parent.parentNode;?}
          ????????
          else?{?parent?=?null;?}
          ????}
          ????
          return?{x:pos[0],?y:pos[1]};
          }?




          主站蜘蛛池模板: 呼玛县| 修文县| 礼泉县| 洛扎县| 永州市| 平陆县| 凯里市| 建德市| 扎兰屯市| 安远县| 宁城县| 九龙城区| 双牌县| 凤台县| 同德县| 井冈山市| 承德县| 竹溪县| 富阳市| 云阳县| 伊金霍洛旗| 武义县| 固原市| 镶黄旗| 荥阳市| 什邡市| 华阴市| 宜兰县| 达拉特旗| 芜湖县| 资溪县| 淮安市| 来安县| 七台河市| 泗阳县| 宁夏| 隆林| 香格里拉县| 饶阳县| 沧源| 宣恩县|