Answered by:
Masterpage, document.body.scrollLeft

Question
-
User32292006 posted
Hello there,
i integrated a drag&drop functionality in my application. My problem is that i cannot retrieve the correct mouse position when the user scrolled the page.
Maybe its because of the Masterpage ? Here is my javascript function, called by document.onmousemove:
function mouseMove() { var x = event.clientX + document.body.scrollLeft; var y = event.clientY + document.body.scrollTop; if (draggedElement != null) { draggedElement.style.top = y; draggedElement.style.left = x; } }
Both, scrollLeft and scrollTop are always 0.
Any hint ? Thanks a lot !
Monday, March 17, 2008 9:15 AM
Answers
-
User798903548 posted
Seems to work for me:
<form id="Form1" method="post" runat="server">
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<input type="button" id="htmlButton" value="Press here" onclick="onButtonClick();">
</form>
<script type="text/javascript">
<!--
function onButtonClick()
{
alert('document.body.scrollLeft: ' + document.body.scrollLeft + ' document.body.scrollTop: ' + document.body.scrollTop);
}
// -->
</script>NC...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 17, 2008 12:05 PM
All replies
-
User798903548 posted
Seems to work for me:
<form id="Form1" method="post" runat="server">
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<input type="button" id="htmlButton" value="Press here" onclick="onButtonClick();">
</form>
<script type="text/javascript">
<!--
function onButtonClick()
{
alert('document.body.scrollLeft: ' + document.body.scrollLeft + ' document.body.scrollTop: ' + document.body.scrollTop);
}
// -->
</script>NC...
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 17, 2008 12:05 PM -
User811641306 posted
I'm having the exact same problem too. Master.master javascript code, always returns 0,0.
Wednesday, May 21, 2008 10:35 PM -
User798903548 posted
I'm having the exact same problem too. Master.master javascript code, always returns 0,0.
Did you try the sample that I posted?
NC...
Thursday, May 22, 2008 8:27 AM -
User811641306 posted
No becuase it's not a master page in your example.
After further searching on the internet I discovered that MS$ decided to move document.body information to document.documentElement on Master pages. So document.documentElement.scrollLeft works.
Thursday, May 22, 2008 9:55 AM -
User798903548 posted
Hmm, you couldn't move that sample into a Master Page example?
Anyways, glad you got it figured out.
NC...
Thursday, May 22, 2008 11:07 AM -
User811641306 posted
That's just it, the code is inside the master page itself. That code inside a master page, then putting hte javascript in question in the .master page, not the .aspx page, will not work.
Thursday, May 22, 2008 11:44 AM