在拖动div的时候
点击div 然后就可以拖动 但是在拖动的时候很卡 鼠标移动太快 div就会停在那里 不跟着鼠标移动
如果再次点击刚才拖动的div 随意拖动都不会卡
到底是哪里出了问题呢?
//js代码--------------------------------------------------------------------------
$(document).ready(function() {
var p1=new Endrag('section-head', 'section','inner-section');
});
function Endrag(source,target,innermove){
innermove=typeof(innermove)=="object" ? innermove:document.getElementById(innermove);
var x0=0,y0=0,moveable=false,index=100,NS=(navigator.appName=='Netscape');
if($('#' + source)){
//鼠标点击div
$('#' + source).mousedown(function(e){
var event_mousedown = e;
if (e.target.className == '') {
location.href = e.target.href;
return;
}
everdivheight = $('#' + target).height();
$('#' + target + ' .progress-indicator').show();
$('#' + target).css('background','#ddd').css('color','#ddd').css('position','relative');
everdivhtmlheader = $('#' + target + ' .show-div-h').html();
everdivhtmlcontent = $('#'+target+ ' .show-div-c').html();
$('#' + target + ' .show-div-h').html('');
$('#' + target + ' .show-div-c').html('');
$('#' + target).css('height', everdivheight);
e = e ? e : (window.event ? window.event : null);
if(e.button==(NS)?0 :1) {
if(!NS){this.setCapture();}
x0 = e.pageX ;
y0 = e.pageY ;
moveable = true;
} });
//拖动;
var position_top = 0;
var position_now_top = 0;
$('#'+source +'-inner').mousemove(function(e){
e = e ? e : (window.event ? window.event : null);
if(moveable){
innermove.style.left = (e.pageX-x0 ) +"px";
innermove.style.top = (e.pageY-y0 ) +"px";
if(position_top == 0) {
position_top = innermove.style.top;
position_top = parseInt(position_top.replace('px',''));
}
position_now_top = innermove.style.top;
position_now_top = parseInt(position_now_top.replace('px',''));
}
position_top = position_now_top;
});
//停止拖动;
$('#'+source+'-inner').mouseup(function (e){
if(moveable) {
if(!NS){this.releaseCapture();}
moveable = false;
}
$('#'+target +' .progress-indicator').animate({left: 0,top: 0},"slow","",function(){
$(this).hide();
$('#'+target).css('background','').css('color','').css('position','static');
$('#'+target+' .show-div-h').append(everdivhtmlheader);
$('#'+target+' .show-div-c').append(everdivhtmlcontent); });
});
}
}
html代码----------------------------------------------------------------------------------
<div id="section" class="section moved" >
<div id="section-head" class="header show-div-h">
<h2 class='title-other'>简介
</h2>
</div>
<div class="content show-div-c"> <div class="profile-supply">
<h3>专长</h3>
<p> </p>
</div>
</div>
<div class="progress-indicator" id="inner-section">
<div id="section-head-inner" class="header">
<h2 class='title-other'>简介
</h2>
</div>
<div class="content"> <div class="profile-supply">
<h3>专长</h3>
<p>
</p>
</div>
</div>
</div>
</div> <!-- .section -->
---------------------------------------------------------------------------------------
跪求解答!!!!
点击div 然后就可以拖动 但是在拖动的时候很卡 鼠标移动太快 div就会停在那里 不跟着鼠标移动
如果再次点击刚才拖动的div 随意拖动都不会卡
到底是哪里出了问题呢?
//js代码--------------------------------------------------------------------------
$(document).ready(function() {
var p1=new Endrag('section-head', 'section','inner-section');
});
function Endrag(source,target,innermove){
innermove=typeof(innermove)=="object" ? innermove:document.getElementById(innermove);
var x0=0,y0=0,moveable=false,index=100,NS=(navigator.appName=='Netscape');
if($('#' + source)){
//鼠标点击div
$('#' + source).mousedown(function(e){
var event_mousedown = e;
if (e.target.className == '') {
location.href = e.target.href;
return;
}
everdivheight = $('#' + target).height();
$('#' + target + ' .progress-indicator').show();
$('#' + target).css('background','#ddd').css('color','#ddd').css('position','relative');
everdivhtmlheader = $('#' + target + ' .show-div-h').html();
everdivhtmlcontent = $('#'+target+ ' .show-div-c').html();
$('#' + target + ' .show-div-h').html('');
$('#' + target + ' .show-div-c').html('');
$('#' + target).css('height', everdivheight);
e = e ? e : (window.event ? window.event : null);
if(e.button==(NS)?0 :1) {
if(!NS){this.setCapture();}
x0 = e.pageX ;
y0 = e.pageY ;
moveable = true;
} });
//拖动;
var position_top = 0;
var position_now_top = 0;
$('#'+source +'-inner').mousemove(function(e){
e = e ? e : (window.event ? window.event : null);
if(moveable){
innermove.style.left = (e.pageX-x0 ) +"px";
innermove.style.top = (e.pageY-y0 ) +"px";
if(position_top == 0) {
position_top = innermove.style.top;
position_top = parseInt(position_top.replace('px',''));
}
position_now_top = innermove.style.top;
position_now_top = parseInt(position_now_top.replace('px',''));
}
position_top = position_now_top;
});
//停止拖动;
$('#'+source+'-inner').mouseup(function (e){
if(moveable) {
if(!NS){this.releaseCapture();}
moveable = false;
}
$('#'+target +' .progress-indicator').animate({left: 0,top: 0},"slow","",function(){
$(this).hide();
$('#'+target).css('background','').css('color','').css('position','static');
$('#'+target+' .show-div-h').append(everdivhtmlheader);
$('#'+target+' .show-div-c').append(everdivhtmlcontent); });
});
}
}
html代码----------------------------------------------------------------------------------
<div id="section" class="section moved" >
<div id="section-head" class="header show-div-h">
<h2 class='title-other'>简介
</h2>
</div>
<div class="content show-div-c"> <div class="profile-supply">
<h3>专长</h3>
<p> </p>
</div>
</div>
<div class="progress-indicator" id="inner-section">
<div id="section-head-inner" class="header">
<h2 class='title-other'>简介
</h2>
</div>
<div class="content"> <div class="profile-supply">
<h3>专长</h3>
<p>
</p>
</div>
</div>
</div>
</div> <!-- .section -->
---------------------------------------------------------------------------------------
跪求解答!!!!
http://www.websjy.com/bbs/viewthread.php?tid=42612、javascript实现可以拖动的层示例(层拖动,兼容IE/FF)http://www.websjy.com/bbs/viewthread.php?tid=2665