Teensweb
New Member
- Messages
- 352
- Reaction score
- 1
- Points
- 0
hi every one, I needed a (java)script to make a division draggable and got the following code from dynamicdrive:
Now an html page with the following code:
Now everything works fine as intended:On clicking the '<a onclick="ftoggle('player')">click</a>' , the visibility of the layers: "icon" and "player" toggles and the layer player is draggable and works smoothly.
But the problem begins when i add an iframe to the body, on doing so, the script slows terribly on firefox 3.6 and google chrome , but works well on ie.
here's the iframe code that i added:
Can someone help me modify the script so that it uses less memory load, and works smoothly?
(I have 1 gb of RAM and am not experiencing any other speed troubles)
- I am using the IM script from fleaim.com and the script used to drag the IM box in that page works fine even with iframes.
So it would be even fine if someone can get me some script like that since For some reason or the other I cant figure out how that one works!
Thanx in advance.
Code:
var dragobject =
{z: 0, x: 0, y: 0, offsetx: null, offsety: null, targetobj: null, dragapproved: 0, initialize: function()
{document.onmousedown = this.drag;
document.onmouseup = function()
{
this.dragapproved = 0;
};
}
, drag: function(e)
{var a = window.event ? window.event: e;
this.targetobj = window.event ? event.srcElement: e.target;
if (this.targetobj.className == "draggable")
{ this.dragapproved = 1;
if (isNaN(parseInt(this.targetobj.style.left)))
{this.targetobj.style.left = 0;
}
if (isNaN(parseInt(this.targetobj.style.top)))
{this.targetobj.style.top = 0;
}
this.offsetx = parseInt(this.targetobj.style.left);
this.offsety = parseInt(this.targetobj.style.top);
this.x = a.clientX;
this.y = a.clientY;
if (a.preventDefault) a.preventDefault();
document.onmousemove = dragobject.moveit;
}
}
, moveit: function(e)
{var a = window.event ? window.event: e;
if (this.dragapproved == 1)
{this.targetobj.style.left = this.offsetx + a.clientX - this.x + "px";
this.targetobj.style.top = this.offsety + a.clientY - this.y + "px";
return false;
}
}
};
dragobject.initialize();
function ftoggle(id) //I added this myself...
{document.getElementById(id).style.display = "";
if (document.getElementById(id).style.visibility == "hidden")
{document.getElementById('icon').style.display = "none";
document.getElementById(id).style.visibility = "";
}
else
{document.getElementById(id).style.visibility = "hidden";
document.getElementById('icon').style.display = "";
}
}
HTML:
<style type="text/css">
#player {
background: url('m.png') no-repeat -1px 0;
cursor:move;
position:relative;
z-index:100;
height:250px;
width:192px;
}
#f {
height:260px;
position:absolute;
top:26px;
}
#c {
position:absolute;
right:7px;
top:7px;
}
</style>
<div id="player" style="display:none; visibility:hidden;" class="draggable">
<div id="c"><img style="cursor:pointer" src="min.png" onclick="ftoggle('player')"/></div>
<div id="f">
<iframe scrolling="no" frameborder="0" style="height:2580px; width:200px;" src="player/index.html"></iframe>
</div>
</div>
<div id="icon">
<a onclick="ftoggle('player')">click</a>
</div>
But the problem begins when i add an iframe to the body, on doing so, the script slows terribly on firefox 3.6 and google chrome , but works well on ie.
here's the iframe code that i added:
HTML:
<div style="position:absolute; top:0px;width:100%;height:100%; z-index:0;">
<iframe id="frame" src="websiteurl" scrolling="auto" marginwidth="0" marginheight="0" frameborder="0" class="c1" name="frame" ></iframe>
</div>
(I have 1 gb of RAM and am not experiencing any other speed troubles)
- I am using the IM script from fleaim.com and the script used to drag the IM box in that page works fine even with iframes.
So it would be even fine if someone can get me some script like that since For some reason or the other I cant figure out how that one works!
Thanx in advance.
Last edited: