/    Sign up×
Community /Pin to ProfileBookmark

Moving Iframe within iframe example.

Hello all

Thanks for all the help!

I’ve wrote a script which moves an iframe when pressing it and moving it around. Anyhow, for now this is only a FF solutions so IE is left off.
My problem is that the iframe does not have the flow I would like when moving it. It jumps a bit and this couses a unprofessional look.

Here’s the code. Very simple stuff.

Javascript:

window.onload = function (){
var iframe = document.getElementById(‘myiframe1’);
iframe.contentDocument.body.innerHTML = ‘Move me, but i have a hangover..’
iframe.contentDocument.parent = iframe;
iframe.contentDocument.addEventListener(‘mousedown’, movetoolbox, false);

var iframe = document.getElementById(‘myiframe2’);
iframe.contentDocument.body.innerHTML = ‘Move me, but im a bit shaky..’
iframe.contentDocument.parent = iframe;
iframe.contentDocument.addEventListener(‘mousedown’, movetoolbox, false);

}

function movetoolbox(event) {
if(event.type == ‘mousemove’){
this.addEventListener(‘mouseout’, movetoolbox, false);
this.addEventListener(‘mouseup’, movetoolbox, false);
this.parent.style.top = (parseInt(this.parent.style.top) – (-parseInt(event.clientY))) – this.firstposY + ‘px’
this.parent.style.left = (parseInt(this.parent.style.left) – (-parseInt(event.clientX))) – this.firstposX + ‘px’
}

if(event.type == ‘mousedown’){
this.firstposY = event.clientY
this.firstposX = event.clientX
this.addEventListener(‘mousemove’, movetoolbox, false);
}

if (event.type == ‘mouseout’ || event.type == ‘mouseup’){
this.removeEventListener(‘mousemove’, movetoolbox, false);
}

}

HTML

<iframe id=”myiframe1″ style=”position:absolute; top:300px;left:300px;width:400px;height:350px;border:1px dotted red;background:white;z-index:1;”></iframe>
<iframe id=”myiframe2″ style=”position:absolute; top:100px;left:300px;width:200px;height:150px;border:1px dotted green;background:white;z-index:2;”></iframe>

Here’s a live example: [url]http://www.moonlite.se/scripts/dom/moveiframe/[/url]
Hope someone have a bit of idees how to fix these hicks.

Best regards ?
/Adrian

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@ananiasJul 15.2006 — Perhaps you have a slow machine. On my Mac G5, in Safari, they both move with total clarity as smoothly as the mouse itself.
Copy linkTweet thisAlerts:
@amccoolauthorJul 15.2006 — Yes in Safari it's smooth. I didn't test it there.

But in FF it's still messy. Do you know a solution?

Thanks!
Copy linkTweet thisAlerts:
@JMRKERJul 15.2006 — Works smoothly for me in FF.

I guess I don't see the problem. :o
Copy linkTweet thisAlerts:
@amccoolauthorJul 15.2006 — What the hell...

Are you using PC or Mac? I use FF on Mac, might be that.

Ananias, please can you test it in FF on your G5? Please.
Copy linkTweet thisAlerts:
@JMRKERJul 15.2006 — Using PC clone with Home-XP
Copy linkTweet thisAlerts:
@ananiasJul 15.2006 — Ananias, please can you test it in FF on your G5? Please.[/QUOTE]You're right. FF acts just like's it's got an advanced case of Parkinson's Disease. I reckon it's on account of the [url="http://www.quirksmode.org/js/events_compinfo.html#prop"]event model[/url] you're using. I suspect that if you rework it to use what Peter-Paul Koch calls the traditional model (scroll up a bit on his page to see how) these problems will go away.
Copy linkTweet thisAlerts:
@ananiasJul 16.2006 — If I was trying to make this work, I'd start by taking out all but the essential uses of the [b]this[/b] object.
Copy linkTweet thisAlerts:
@klanga2049Jul 18.2006 — Sorry that I can't hint you at a solution, but here is what I get on 2 different laptops both running XP and latest Opera browser:

(Older laptop, Intel III 866MhZ, 500MB RAM) shaky issues as you describe, can't even move the iframes in index1.html (stops after moving marginally).

(Latest laptop, Dual core T2500 2GHz, 1GB RAM): very smooth, no jittering.

I hope this helps.
Copy linkTweet thisAlerts:
@amccoolauthorJul 18.2006 — Thanks for the help, I will try some ways of fixing it.
×

Success!

Help @amccool spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...