Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js] dynamiczna pozycja diva
zibra
post
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 26.10.2005
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Witam!

Potrzebuję stworzyć skrypt, który dynamicznie ustawi diva nad stroną w zależności od scrollowania i szerokości / wysokości okna przeglądarki.
W jaki sposób do tego podejść, tak aby stworzyć dwie funkcje obliczające odległość od górnego marginesu przeglądarki i od lewego marginesu, a następnie wartości przez nie obliczane dynamicznie podstawiane były do position: absolute; left: ... ; top: ...
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
zibra
post
Post #2





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 26.10.2005
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Dzięki wielkie za pomoc lord_t (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) udało się osiągnąć oczekiwany efekt. Dla ciekawych: www.herbacin.pl/index1.php?dz=produkty - menu w lewej kolumnie.

Kod dla potomnych, oczywiście w bb code (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) :
  1. function getScrollHeight()
  2. {
  3. var h = window.pageYOffset ||
  4. document.body.scrollTop ||
  5. document.documentElement.scrollTop;
  6.  
  7. return h ? h : 0;
  8. }
  9. function pageWidthf(){
  10. var windowWidth;
  11. if (self.innerWidth) {
  12. windowWidth = self.innerWidth;
  13. } else if (document.documentElement && document.documentElement.clientWidth) {
  14. windowWidth = document.documentElement.clientWidth;
  15. } else if (document.body) {
  16. windowWidth = document.body.clientWidth;
  17. }
  18. return windowWidth;
  19. }
  20. function changePosition(){
  21. var roznica;
  22. if(navigator.appName == "Microsoft Internet Explorer"){
  23. roznica = 428;
  24. }else{
  25. roznica = 437;
  26. }
  27. document.getElementById('menudiv').style.position='absolute';
  28. if(getScrollHeight() > 230){
  29. document.getElementById('menudiv').style.top=(getScrollHeight() + 35) + 'px';
  30. }else{
  31. document.getElementById('menudiv').style.top=265 + 'px';
  32. }
  33. document.getElementById('menudiv').style.left=(pageWidthf()/2 - roznica) + 'px';
  34. }
  35. setInterval("changePosition();", 10);
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 18:27