473,396 Members | 2,050 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.

Making a drag-scroller cross-browser compatible

I've not seen any real sollutions to this yet. I found something similar on this forum but the posted sollutions didn't work.

I would like to make a drag to scroll for my blog, using JS. So far I have written the following (for use in Firefox):

Expand|Select|Wrap|Line Numbers
  1. document.onmousedown = function(){
  2.     var e = arguments[0]||event;
  3.     var x = e.pageX;
  4.     var y = e.pageY;
  5.  
  6.     document.onmousemove = function(){
  7.         scrollTo(e.pageX - x), y - e.pageY);
  8.     }
  9.  
  10.     document.onmouseup = function(){
  11.         document.onmousemove = null;
  12.     }
  13. }
  14.  
BTW I am totally new to JS so go easy on me ;D

I have the sollution for IE, however can't get the above working properly in Firefox. The logic is here but it appears to scroll in large jerks downwards. Any ideas?

Check this page out for a script I located (IE only). It shows what my objective is:
http://javascript.internet.com/page-...roll-page.html

I would be greatful for any help getting this multi-browser compatible :D
Aug 16 '07 #1
6 2513
pbmods
5,821 Expert 4TB
Heya, frankenstein. Welcome to TSDN!

Changed thread title to better describe the problem (did you know that threads whose titles contain three words or less actually get FEWER responses?).
Aug 16 '07 #2
Thanks for welcome and help pbmods.

Any ideas about a possible sollution. Cheers ;D
Aug 16 '07 #3
iam_clint
1,208 Expert 1GB
Example
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. //Example provided by iam_clint (www.thescripts.com)
  3. var x=0;
  4. var y=0;
  5. var posx=0;
  6. var posy=0;
  7. var isNN = detectBrowser();
  8. if (isNN=="firefox") { isNN = true; } else { isNN = false; }
  9. function detectBrowser() {
  10.     var browser=navigator.userAgent;
  11.     if (browser.indexOf("Firefox")>0) { return "firefox"; }
  12.     if (browser.indexOf("MSIE")>0) { return "ie"; }
  13. }
  14.  
  15. document.onmousedown = handleMouseDown;
  16. function handleMouseDown(e) {
  17.     if (detectBrowser()=="firefox") { document.captureEvents(Event.MOUSEMOVE); }
  18.     MousePos(e);
  19.     posx=document.body.scrollLeft+x;
  20.     posy=document.body.scrollTop+y;
  21.     document.onmousemove = doScrolling;
  22.     document.onmouseup = handleMouseUp;
  23.     return false;
  24. }
  25.  
  26.  
  27. function handleMouseUp() {
  28.     document.onmousemove = null;
  29.     document.body.style.cursor = "";
  30. }
  31.  
  32. function doScrolling(e){
  33.     MousePos(e);
  34.     document.getElementById("xy").style.top = document.body.scrollTop;
  35.     document.getElementById("xy").style.left = document.body.scrollLeft;
  36.     document.getElementById("xy").innerHTML = "x: "+x+" y: "+y+"<br>posx: "+posx+" posy: "+posy+"<br>x-posx: "+Math.floor(x-posx)+" y-posy: "+Math.floor(y-posy);
  37.     scrollTo(posx-x, posy-y);
  38.     document.body.style.cursor = "move";
  39.     return false;
  40. }
  41. function MousePos(e) {
  42.     x = isNN ? x = e.pageX : x = window.event.clientX;
  43.     y = isNN ? y = e.pageY : y = window.event.clientY; 
  44. }
  45. </script>
  46. <body>
  47. <div id="xy" style="position: absolute; top: 0px; left: 0px; width: 180px;"></div>
  48. <table height="5000" width="5000"><tr><td>TEST</td></tr></table>
  49. </body>
  50.  
Aug 16 '07 #4
Wow! That's awesome. Thank you so much. I will post a link when I have the design complete :D
Aug 16 '07 #5
pbmods
5,821 Expert 4TB
Heya, Frankenstein.

Very nice. Works great in Safari :)

Good luck with your project, and if you ever need anything, post back anytime :)
Aug 19 '07 #7

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

Similar topics

1
by: Han-Wen Nienhuys | last post by:
Hi there, this might not be the right group to ask, but I'm looking for some hints on making a drag & droppable application on MacOS X. I succeeded in producing a bundle that calls a python...
8
by: slawek | last post by:
Hi i have following stylesheet: ..linklist { width: 100%; font-size: 75%; background: #EEEEEE; margin: 5px; height: 300px; overflow: auto;
0
by: Andy | last post by:
I'm just making a small app with two tree views using drag and drop functionality. However, there is a small problem: 1) I select a node using the mouse: I'm locating the node, selecting it by...
0
by: Dave | last post by:
I'm creating a custom control. To start, I created the control in a seperate project in the same solution. I didn't change anything from the template vs.net creates for a web custom control, I...
0
by: haegens | last post by:
I am making a .NET Application which has a TreeView Control in it. I have 3 levels of nodes. The toplevel is a rootnode which contains all other nodes. The second level holds one kind of nodes that...
2
by: dejavue82 | last post by:
Dear ASP.NET programmers, I have noticed many asp.net 2.0 programmers mention that web applications created with the use of Visual Studio wizards and by draging and droping fom the toolbox are...
2
by: Harshad | last post by:
Hi, I'm writing a program using Python 2.4 and PyQt4. The aim is to implement drag and drop from filesystem and display a list of files dragged on to the listWidget. This function will later...
1
by: SteveDouglas | last post by:
Hi all, I am currently writing an application in VB.NET that has a lot of controls (treeviews/listviews/labels and so forth) that represent "things" that need to be draggable from place to place,...
6
by: 123shailesh | last post by:
Hello everyone, I need some help. I have been working on it for some time but havent been able to think of any solution. Even had thought of making do without it, even though it was a major part...
1
by: JHuman | last post by:
Hi there, At the moment I'm making an application where I drag an item in a List to a Canvas (all in SWT). However, I don't wish to use TextTransfer or ByteArrayTransfer for the drag and drop data...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.