jquery.js 与一个js有冲突。 错误提示:'root.style.left' 为空或不是对象
这个位置如下代码。请问如何修改呢?是一个弹出窗口代码。
var Drag={
    "obj":null,
"init":function(handle, dragBody, e){
if (e == null) {
handle.onmousedown=Drag.start;
}
handle.root = dragBody; if(isNaN(parseInt(handle.root.style.left)))handle.root.style.left="0px";
if(isNaN(parseInt(handle.root.style.top)))handle.root.style.top="0px";
handle.root.onDragStart=new Function();
handle.root.onDragEnd=new Function();
handle.root.onDrag=new Function();
if (e !=null) {
var handle=Drag.obj=handle;
e=Drag.fixe(e);
var top=parseInt(handle.root.style.top);
var left=parseInt(handle.root.style.left);
handle.root.onDragStart(left,top,e.pageX,e.pageY);
handle.lastMouseX=e.pageX;
handle.lastMouseY=e.pageY;
document.onmousemove=Drag.drag;
document.onmouseup=Drag.end;
}
},
"start":function(e){
var handle=Drag.obj=this;
e=Drag.fixEvent(e);
var top=parseInt(handle.root.style.top);
var left=parseInt(handle.root.style.left);
//alert(left)
handle.root.onDragStart(left,top,e.pageX,e.pageY);
handle.lastMouseX=e.pageX;
handle.lastMouseY=e.pageY;
document.onmousemove=Drag.drag;
document.onmouseup=Drag.end;
return false;
},
"drag":function(e){
e=Drag.fixEvent(e);

var handle=Drag.obj;
var mouseY=e.pageY;
var mouseX=e.pageX;
var top=parseInt(handle.root.style.top);
var left=parseInt(handle.root.style.left);

if(isIE){Drag.obj.setCapture();}else{e.preventDefault();};//作用是将所有鼠标事件捕获到handle对象,对于firefox,以用preventDefault来取消事件的默认动作: var currentLeft,currentTop;
currentLeft=left+mouseX-handle.lastMouseX;
currentTop=top+(mouseY-handle.lastMouseY);
handle.root.style.left=currentLeft +"px";
handle.root.style.top=currentTop+"px";
handle.lastMouseX=mouseX;
handle.lastMouseY=mouseY;
handle.root.onDrag(currentLeft,currentTop,e.pageX,e.pageY);
return false;
},
"end":function(){
if(isIE){Drag.obj.releaseCapture();};//取消所有鼠标事件捕获到handle对象
document.onmousemove=null;
document.onmouseup=null;
Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top));
Drag.obj=null;
},
"fixEvent":function(e){//格式化事件参数对象
var sl = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
var st = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
if(typeof e=="undefined")e=window.event;
if(typeof e.layerX=="undefined")e.layerX=e.offsetX;
if(typeof e.layerY=="undefined")e.layerY=e.offsetY;
if(typeof e.pageX == "undefined")e.pageX = e.clientX + sl - document.body.clientLeft;
if(typeof e.pageY == "undefined")e.pageY = e.clientY + st - document.body.clientTop;
return e;
}
};

解决方案 »

  1.   

    missccc
    (中国人人民民)
    等 级:
    结帖率:100.91%csdn出错了吧。。
      

  2.   

    代码贴全一点,看不出是否可以取到这个对象root.style.left
      

  3.   

    代码太多了,贴不了,地址如下,就是这个js:http://tj.zhuatu.com/Dialog.js
    麻烦高手看看。谢谢。
      

  4.   

    明显是找不到handle.root这个对象,跟jquery毛关系都没有。。
      

  5.   

    要是跟jquery有冲突 那你就去掉jquery引用  看看是不是还有冲突..
      

  6.   

    8楼、9楼高手说的对,好像不是和jquery有冲突。
    我的代码用途:jquery.js和js.js是实现瀑布流。单独运行没问题。
    Dialog.js 这是一个弹出窗口效果,单独运行没问题。测试发现问题如下:我的页面如果下面这样的顺序调用就没有任何错误提示,但是瀑布流有问题,他是横着排每一行都顶端对齐,正常的不是顶端对齐的,是随机插入。
    <SCRIPT type=text/javascript src="jquery.js"></SCRIPT>
    <script type="text/javascript" src="Dialog.js"></script> //这是一个弹出窗口效果。
    <script type="text/javascript" src="js.js"></script>
    <script type="text/javascript">
    $(function(){
        zhuatu.init_page_layout();
    });
    </script>换了无数次js的调用顺序,要不就是弹出窗口有问题,要不就是瀑布问题。不能做到都没问题。
    js.js的代码如下,麻烦高手帮我看看。追加100分:var zhuatu={tmblog_app_key:"",show_notify_bar:function(e,c,b){if(!c){c="info"}switch(c){case"info":var a="#FFF";var d="#1E90FF";break;case"error":var a="#FFF";var d="red";break;case"warn":var a="#FFFFCC";var d="#FF6600"}if(!b){b=3000}$.show_notify_bar({color:d,background_color:a,position:"top",removebutton:true,message:e,time:b,container:"#doc3"})}};zhuatu.install_ajax_hooks=function(){$("form.ajax-form").livequery(function(){$(this).ajaxForm()});$("a.confirm-request").live("click",function(){if(confirm("确认执行这个操作吗?")){$.get($(this).attr("href"))}return false});$("a.ajax-request").live("click",function(){try{$(this).poshytip("hide");$(this).poshytip("destory")}catch(a){}$.get($(this).attr("href"));return false});$("a.submit-button").live("click",function(){try{$(this).parent("form").submit()}catch(a){}return false});$("a.show_tip").livequery(function(){$(this).poshytip({className:"tip-twitter",showTimeout:1,alignTo:"target",alignX:"center",offsetY:5,allowTipHover:false,fade:false,slide:false})});$(".pretty-tip").livequery(function(){$(this).poshytip({className:"tip-twitter",showTimeout:1,alignTo:"target",alignX:"center",offsetY:5,allowTipHover:false,fade:false,slide:false})});$(".facebox-popup").facebox_any();$(".reply_message").bind("click",function(){var a=this.name;$("#reply_to_user").val(a)})};zhuatu.site_track=function(){function a(b,c){$(b).click(function(){$(this).attr("href",$(this).attr("href")+"?ref="+c)})}a("#site_logo","site_logo");a("ul.main-nav a","main_nav");a("#stuff_list_sidebar a","stuff_list_sidebar");a("#dashboard_latest a","dashboard_latest");a("#dashboard_hot a","dashboard_hot");a("#dashboard_timeline a","dashboard_timeline");a("#dashboard_tops a","dashboard_tops");a("#home_hot_tags a","home_hot_tags");a("#stuff_quick_search a","stuff_quick_search")};zhuatu.check_user_notice=function(a){setTimeout(function(){$.get(a+"?.preventCache="+Math.random()*35)},2)};zhuatu.make_list_item_hover=function(){$(".box").livequery(function(){$(this).hover(function(){$(this).addClass("active")},function(){$(this).removeClass("active")})});$(".admin-box").livequery(function(){$(this).hover(function(){$(this).children(".admin-btn-box").show()},function(){$(this).children(".admin-btn-box").hide()})});$(".admin-btn-box a").livequery(function(){$(this).poshytip({className:"tip-twitter",showTimeout:1,alignTo:"target",alignX:"center",offsetY:5,allowTipHover:false,fade:false,slide:false})})};zhuatu.init_page_layout=function(){$("ul.sf-menu").superfish();$(".side-nav h3").click(function(){$(this).next(".tabs-box").toggle();$(this).find(".arrow").toggleClass("up")});$(".masonry-box").masonry({singleMode:true,columnWidth:$(".masonry-box .box").outerWidth(true),resizeable:false});$(window).resize(function(){$(".masonry-box").masonry({columnWidth:$(".masonry-box .box").outerWidth(true)})});};