AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Html-Seite automatisch scrollen (JavaScript)

Html-Seite automatisch scrollen (JavaScript)

Ein Thema von Woyzeck · begonnen am 13. Sep 2009 · letzter Beitrag vom 5. Apr 2011
 
Benutzerbild von rollstuhlfahrer
rollstuhlfahrer

Registriert seit: 1. Aug 2007
Ort: Ludwigshafen am Rhein
1.529 Beiträge
 
Delphi 7 Professional
 
#13

AW: Html-Seite automatisch scrollen (JavaScript)

  Alt 30. Mär 2011, 14:47
Den benutze ich für Hoch/Runter für Anker:
Code:
//var scrollSteps = 200
var scrollSteps = 50;
var timer="";

function scrollWin(anchorID) {
   if (navigator.userAgent.indexOf("Opera") == -1){ // not Opera
      var s,d;
      var test1 = document.body.scrollHeight;
      var test2 = document.body.offsetHeight
      if (test1 > test2) // all but Explorer Mac
      {
         s = document.body.scrollWidth;
         d = document.body.scrollHeight;
      }
      else // Explorer Mac;
      {    //would also work in Explorer 6 Strict, Mozilla and Safari
         s = document.body.offsetWidth;
         d = document.body.offsetHeight;
      }

      var a,b;
      if (self.innerHeight) // all except Explorer
      {
         a = self.innerWidth;
         b = self.innerHeight;
      }
      else if (document.documentElement && document.documentElement.clientHeight)
         // Explorer 6 Strict Mode
      {
         a = document.documentElement.clientWidth;
         b = document.documentElement.clientHeight;
      }
      else if (document.body) // other Explorers
      {
         a = document.body.clientWidth;
         b = document.body.clientHeight;
      }


      var y;
      if (self.pageYOffset) // all except Explorer
      {
         y = self.pageYOffset;
      }
      else if (document.documentElement && document.documentElement.scrollTop)
         {   // Explorer 6 Strict
            y = document.documentElement.scrollTop;
         }
         else if (document.body) // all other Explorers
         {
            y = document.body.scrollTop;
         }

      var id = anchorID.substring(anchorID.indexOf("#")+1,anchorID.length)
      clearTimeout(timer)

      if (y <= document.getElementById(id).offsetTop-scrollSteps)
      {   // scroll down
         window.scrollBy(0,scrollSteps);
         timer=setTimeout("scrollWin('"+id+"')",10);

         if(y > (d-b)-scrollSteps){
            clearTimeout(timer);
            y = d-b;
         }

      }
      else
      {
         if(y >= document.getElementById(id).offsetTop+scrollSteps)
         {   // scroll up
            window.scrollBy(0,-scrollSteps)
            timer=setTimeout("scrollWin('"+id+"')",10)
         }
         else
         {   // scroll the last bit (smaller than scrollSteps)
            window.scrollBy(0, document.getElementById(id).offsetTop- y);
            clearTimeout(timer)
            y = document.getElementById(id).offsetTop
         }
      }
   return false;
   }
return true;
}
Das kann man jetzt noch für Rechts/Links erweitern. Aber wie man hier sieht: Opera ist außen vor.

Bernhard

ADD:

a) Herzlich willkommen in der DP

b) Auch wenn ich jetzt schon geantwortet habe: Lieber nen neuen Thread aufmachen.
Bernhard
Iliacos intra muros peccatur et extra!
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz