Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Google maps like - scrolling image
Old 03-31-2009, 06:51 PM Google maps like - scrolling image
Experienced Talker

Posts: 37
Name: Paul
Trades: 0
http://maps.google.com/

I have a really large image and I need to be able to drag & scroll it with my mouse just like google maps.

This is what I came up with:

Code:
<script language="JavaScript1.2">

var nn6=document.getElementById&&!document.all;
var isdrag=false;
var x = 0;
var y = 0;

function movemouse(e){
	
if(isdrag){

document.getElementById('lista').scrollLeft -=  (nn6 ? e.clientX - x : event.clientX - x);
document.getElementById('lista').scrollTop -= (nn6 ? e.clientY - y : event.clientY - y);

return false;
}
}

function selectmouse(e) {
	x = nn6 ? e.clientX : event.clientX;
	y = nn6 ? e.clientY : event.clientY;
	isdrag = true;
	document.onmousemove=movemouse;
	return false;
}
function mouseup(e){
	isdrag = false;
}

document.onmousedown=selectmouse;
document.onmouseup=mouseup;

</script>

====================== HTML ==================


<div style="overflow:hidden; width: 500px; height: 400px;">
<img src="VERY LARGE IMAGE" />
</div>

^ this partially works, but the more you scroll to left or right, the faster it moves. Look at the live demo:

http://www.scape-xp.com/world_map.php



does anyone have an idea why it's behaving like this?
__________________
eh79+
Athlon1600 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-01-2009, 02:02 PM Re: Google maps like - scrolling image
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Not sure at first glance, but it could have something to do with the fact that you are attaching the onmousemove event every time there is an onmousedown event. This is going to create memory leaks, regardless, so it would be better to only attach this event once, then determine if action should be taken via your "isdrag" variable.

I suspect something in your math is funny.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-01-2009, 08:07 PM Re: Google maps like - scrolling image
Experienced Talker

Posts: 37
Name: Paul
Trades: 0
EDIT:

you were right. My math is wrong.
After each mouse move, I had to update x and y variables again so that they could be compared on the next mousemove(e) event instead of using the same x and y from the very first click.

here is what I added:

Code:
function movemouse(e){
	
if(isdrag){

document.getElementById('lista').scrollLeft -=  (nn6 ? e.clientX - x : event.clientX - x);
x = nn6 ? e.clientX: event.clientX;
document.getElementById('lista').scrollTop -= (nn6 ? e.clientY - y : event.clientY - y);
y = nn6 ? e.clientY : event.clientY;

return false;
}
}
works perfectly. Problem solved
__________________
eh79+

Last edited by Athlon1600; 04-01-2009 at 10:17 PM..
Athlon1600 is offline
Reply With Quote
View Public Profile
 
Old 04-01-2009, 10:47 PM Re: Google maps like - scrolling image
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Good work
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-16-2009, 03:49 AM Re: Google maps like - scrolling image
Junior Talker

Posts: 1
Name: Akshay
Trades: 0
Hello ,
Nice effect , but when i try this is in Mozila FireFox the code is not working properly, when we click mouse to drag image , image get stick to mouse and till next click it get attached to mouse and move according to mouse direction, is there any solution for this ...please reply .... thank you.

Sir, Really nice job.......
cool.akshay is offline
Reply With Quote
View Public Profile
 
Old 08-09-2009, 06:37 PM Re: Google maps like - scrolling image
Experienced Talker

Posts: 37
Name: Paul
Trades: 0
add this piece of code inside selectmouse(e) function:

Code:
if(e.preventDefault) { 
e.preventDefault();
 }

EDIT:

it looks like IE 8 has the same problem.
add this too:
Code:
document.ondragstart = function(){
	return false;
}
__________________
eh79+

Last edited by Athlon1600; 08-09-2009 at 06:52 PM..
Athlon1600 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Google maps like - scrolling image
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33573 seconds with 12 queries