Applet: How an object can be scrolled? - preCharge Forums
It shows that you are unregistered. Please register with us by clicking Here
preCharge Forums


Nav Green LeftNav Right
preCharge Forums > Website Design & Development > Programming > JavaScript » Applet: How an object can be scrolled?


Reply
Tcat Right
 
LinkBack Thread Tools Display Modes Tcat Right
Old 07-03-2006   #1 (permalink)
jordan
Member
 
Join Date: Jul 2006
Age: 44
Posts: 31
Default Applet: How an object can be scrolled?

I want to move an object with mouse (not scrollbar).and get the current position of it..
if u can.. please send a sample code also..

Thanks
Jordan
jordan is offline   Reply With Quote


Old 07-18-2006   #2 (permalink)
Nazir
Member
 
Join Date: Jul 2006
Age: 48
Posts: 45
Default Re: Applet: How an object can be scrolled?

If we assume that the object position is the same as the cursor postion. Then we can use the standard method to find the cursor's position relative to the entire page is via the pageX and pageY properties of the event object. Internet Explorer doesn't support these properties, but it does include some properties that almost the one we want. clientX and clientY are available in Internet Explorer, though they measure the distance from the mouse cursor to the edge of the browser window. In order to find the position of the cursor relative to the entire page, we need to add the current scroll position to these dimentions. To do this we need to use getScrollingPosition function from that solution to retrive the required dimentions.

e.g

function displayCursorPosition(event)
{
if (typeof event == "undefined")
{
event = windows.event;
}

var scrollingPosition=getScrollingPosition();
var cursorPosition = [0, 0];

if (typeof event.pageX != "undefined" &&
typeof event.x != "undefined")
{
cursorPosition[0] = event.pageX;
cursorPosition[1] = event.pageY;
}
else
{
cursorPosition[0] = event.clientX + scrollingPosition[0];
cursorPosition[1] = event.clientY + scrollingPosition[1];
}

var paragraph = document.getElementByTagName("p")[0];

paragraph.replaceChild(document.createTextNode(
"Your mouse is currently located at : "+cursorPosition[0] +
","+cursorPosition[1],
paragraph.firstChild);

return true;
}

clientX/clientY are valid W3C DOM event properties that exist in most browsers, so we can't rely on their existance as an indication that we need to use them. Instead, within our event handler, we test for the existance of pageX. Internet Explorer for Mac does have pageX, but it's an incorrect value, so we must also check for x.x is actually a nonstandard property, but most browsers support it ( the exception being Opera 8+ and Internet Explorer). It's ok that Opera 8+ doesn't support x, because the else statement is actually a cross-browser method for calculating the mouse cursor position except in Safari, which incorrectly gives clientX the same value as pageX. That's why we still need to use both methods of calculting the cursor position.
Nazir is offline   Reply With Quote

Old 10-12-2006   #3 (permalink)
ScottHughes
Senior Member
 
Join Date: Sep 2006
Age: 22
Posts: 460
Default Re: Applet: How an object can be scrolled?

Which browsers will that code work in - assuming the browsers have JavaScript on? I worry about using JavaScript because it can have such different results in various browsers.
__________________
ScottHughes is offline   Reply With Quote

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
What are the events of connection object? agaba175 ASP 0 08-05-2006 08:44 PM
What is files collection in the folder object? agaba175 ASP 0 08-05-2006 08:39 PM
What method of the Server object do you need to use to obtain an instance of the- agaba175 ASP 0 08-05-2006 08:29 PM
What new object in ASP3.0 can be used to gather information about the last - agaba175 ASP 0 08-05-2006 08:27 PM
Waht does the connection object do? agaba175 ASP 0 08-05-2006 08:07 PM


footer left
All times are GMT. The time now is 05:55 PM.

DISCLAIMER: preCharge Risk Management is not responsible for any opinions, advice or comments expressed on the preCharge Community Forums.
preCharge® is a registered trademark of preCharge Risk Management | chargeback protection | Merchant Account Blog

Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC6

Buy Shares | Credit Counseling | Credit Cards | Free Credit Score | Myspace Proxy

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49