473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Draggable DIV to scroll window

69
Hi,

I have been assigned the daunting task of applying coordinate movements of a draggable div with a small box to the scrolling of the current window. Basically the small box represents the viewable content of the website and the draggable div represents the cursor. As the draggable div is moved around the confines of the small box the current window should scroll to a proportional position. Thus if the user drags the div to the top left hand corner of the small box the top right corner of the viewable content is shown. This form of navigation has been devised because the webpage content is expected to fill several screens.

I found an example of what I'm trying to explain here, applied to an image.

How to do Google Maps-Style Scrolling Windows with JavaScript and DHTML

From this I have been able to create the following which works in Firefox but doesn't in IE or Safari.

http://client.isimo.net/sls/site/navTest2.html

I hope you can help.

Thanks,

Sean
Apr 17 '08 #1
3 2248
pronerd
392 Expert 256MB
If you are new to using forums you may find it helpful to Google for and review basic forum etiquette. It will likely improve the number and quality of responses you get. People are limited in how helpful they can be to you by ammount of detail provided. No details have been provided here as to what the failure in IE is, nor what you have tried to debug the problem, or what area of code the problem has been isolated to.

Also it is generally not productive to ask people to debug your code if you are not going to post the relevant code for them to look at.

P.S. Please use code tags when posting code
Apr 17 '08 #2
Sebarry
69
Hi,

Apologies for being unclear. The problem is I can determine how much the small box has been dragged and therefore how much I need the window to scroll but whether I use window.scrollBy or window.scrollTo the scrolling is quite clunky.

Here's my code so far:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (browser.isIE) 
  3. {
  4.     x = window.event.clientX + document.documentElement.scrollLeft
  5.       + document.body.scrollLeft;
  6.     y = window.event.clientY + document.documentElement.scrollTop
  7.       + document.body.scrollTop;
  8. }
  9.  
  10. if (browser.isNS) {
  11.     x = event.clientX + window.scrollX;
  12.     y = event.clientY + window.scrollY;
  13.   }
  14.  
  15. var newXPosition = parseInt(dragObj.elStartLeft + x - dragObj.cursorStartX);
  16. var newYPosition = parseInt(dragObj.elStartTop  + y - dragObj.cursorStartY);
  17.  
  18. dragObj.elNode.style.left = newXPosition + "px";
  19. dragObj.elNode.style.top = newYPosition + "px";
  20.  
  21. if( parseInt( document.getElementById( 'navigation_box_cursor' ).style.top ) < parseInt( previousTop ) )
  22.     yScrollAmount = -(yScrollAmount);
  23.  
  24. if( document.getElementById( 'navigation_box_cursor' ).style.left < previousLeft )
  25.     xScrollAmount = -(xScrollAmount);
  26.  
  27. previousTop = document.getElementById( 'navigation_box_cursor' ).style.top;
  28. previousLeft = document.getElementById( 'navigation_box_cursor' ).style.left;
  29.  
  30. //window.scrollTo( (window.scrollX + xScrollAmount), (window.scrollY + yScrollAmount) );
  31.  
  32.  
Do I need to use setTimeout to make it smoother?

Any help most appreciated.

Thanks,

Sean
Apr 18 '08 #3
pronerd
392 Expert 256MB
I am guessing that the reason you are getting the extream over shooting in IE is that the current scroll offset seems to be getting added twice inside the IE if test.

you are adding the scroll offsets from both the document.documentElement, and document.body. I am guessing you only need one of these.


Expand|Select|Wrap|Line Numbers
  1. x = window.event.clientX + document.documentElement.scrollLeft
  2.  + document.body.scrollLeft;
  3.  
  4. y = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
Apr 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: rdlebreton | last post by:
Hi, Folks! I've been trying to develop my own version of these draggable layers and I have been limiting myself to IE6...for now. I have looked at some other examples to get ideas of creating...
4
by: ojorus | last post by:
Hi! I just wonder how I can save a page's scroll position with javascript. (i'm not a javascript developer) I have a PHP-page with two columns; the left contains a lot of thumbnails, and the right...
5
by: Carl Gilbert | last post by:
Hi I am trying to allow a user of a web site to move an image around the page using draggable Divs. I have tried using some script from http://www.mattkruse.com/. In particular:...
2
by: louissan | last post by:
Hi all, I have a slight problem with IE, when everything works with firefox. The goal is to _create_ boxes using the createElement method. And then making it draggable with the mouse. The code...
0
by: Martin Eyles | last post by:
I want to make a pop-up window with a scroll-bar, which a user can select a value with, and send it back to server. this server will then send back a new page containing that value. Also, opening...
5
by: sam | last post by:
Hi all, I am using documnet.body.scroll to disable the window scroll bar. This works in IE only and not other browsers. Can any one tell me if there is any such method which is cross browser...
69
by: RC | last post by:
I know how to do this in JavaScript by window.open("newFile.html", "newTarget", "scrollbars=no,resizable=0,width=200,height=200"); The browser will open a new window size 200x200, not allow...
6
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value =...
1
by: tehweb | last post by:
Background: I have a fixed position div on the bottom om my page. I have then added a dialog-div into this fixed position one. When I bring up the dialog, everything works if the the scrollTop is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.