Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
serkan sendur serkan sendur is offline Offline Jan 30th, 2008, 10:59 am |
0
when you have long web pages, your users may be confused scrolling within your pages because built-in javascript scrollIntoView method makes the page move suddenly.
ScrollToControl method moves slowly enabling the user to keep track of where he/she is going.
Quick reply to this message  
JavaScript / DHTML / AJAX Syntax
  1. function elementPosition(obj) {
  2. var curleft = 0, curtop = 0;
  3.  
  4. if (obj.offsetParent) {
  5. curleft = obj.offsetLeft;
  6. curtop = obj.offsetTop;
  7.  
  8. while (obj = obj.offsetParent) {
  9. curleft += obj.offsetLeft;
  10. curtop += obj.offsetTop;
  11. }
  12. }
  13.  
  14. return { x: curleft, y: curtop };
  15. }
  16.  
  17. function ScrollToControl(id)
  18. {
  19. var elem = document.getElementById(id);
  20. var scrollPos = elementPosition(elem).y;
  21. scrollPos = scrollPos - document.documentElement.scrollTop;
  22. var remainder = scrollPos % 50;
  23. var repeatTimes = (scrollPos - remainder) / 50;
  24. ScrollSmoothly(scrollPos,repeatTimes);
  25. window.scrollBy(0,remainder);
  26. }
  27. var repeatCount = 0;
  28. var cTimeout;
  29. var timeoutIntervals = new Array();
  30.  
  31. var timeoutIntervalSpeed;
  32. function ScrollSmoothly(scrollPos,repeatTimes)
  33. {
  34. if(repeatCount < repeatTimes)
  35. {
  36. window.scrollBy(0,50);
  37. }
  38. else
  39. {
  40. repeatCount = 0;
  41. clearTimeout(cTimeout);
  42. return;
  43. }
  44. repeatCount++;
  45. cTimeout = setTimeout("ScrollSmoothly('" + scrollPos + "','"+ repeatTimes +"')",10);
  46. }
  47.  
  48. example usage :
  49. ScrollToControl('elementID');
  50. it moves to the control smoothly;
0
yoursram yoursram is offline Offline | Feb 18th, 2008
good
 
0
riaz1983 riaz1983 is offline Offline | Mar 19th, 2008
Hi,
I am very new to php and js.I require the above coding to be used in my task .For using the above java script code snippets how should i write the php coding..and how should i call the functions above ..Kindly help me....

THanks in advance......
 
0
serkan sendur serkan sendur is offline Offline | Mar 19th, 2008
hi riaz, you dont need to involve php to use this javascript. Javascript executes on the client machine whereas php executes on the server. This kind of user interface involved jobs are handled by javascript since no server interaction is required. To use this script just add this script to head section of your page then set your html element id(to which element you want to scroll), then call the ScrollToControl function like this from any of the links or buttons as follows :
<a href="javascript://" onclick="ScrollToControl('elementId');">sample</a>
 
0
Mohan0704 Mohan0704 is offline Offline | May 20th, 2008
I mean, do you absolutely need it?

If it's worth it, then yes.

If it's not, then no.


Sure, you can do that, but don't other people want less complicated scripts?

Also, if an error happens, how do you fix it?
It's pretty long, you know.
 
0
serkan sendur serkan sendur is offline Offline | May 20th, 2008
hi Mohan0704, it is worth it, that is why facebook follows the same pattern when scrolling.
 
0
ayesha789 ayesha789 is offline Offline | Jul 2nd, 2009
How I can use this. its not working . please guide me.
 
0
serkan sendur serkan sendur is offline Offline | Jul 2nd, 2009
 
 

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC