25-10-2007, 19:17
|
|
|
חבר מתאריך: 30.07.05
הודעות: 949
|
|
קבלת גובה (height) של DIV ב-JS
שלום,
כתבתי סקריפט למאין "חלון מבזקים" ב-JS, כדי לא להשתמש ב-marquee (סתם כנסיון).
הסקריפט עובד יופי:
https://2007-uploaded.fresh.co.il/2...5/18498980.html
קוד PHP:
<html> <head> <title> JS Scroll Test </title> <style type="text/css"> div.scroller { height: 30%; width: 20%; text-align: center; overflow: hidden; background-color: #cecece; border: 2px groove #cccccc; position: relative; scrolling: none; top: 35%; left: 40%; } </style> <script> function moveUp(id,step) { var str = String(document.getElementById(id).style.top); var pos = str.length-2; str = str.substring(0, pos); document.getElementById(id).style.top = str - step; // alert(document.getElementById(id).style.height); if (str < -350) { document.getElementById(id).style.top = 350 } } setInterval("moveUp('text', 5)", 80); </script> </head> <body>
<div class="scroller" id="news"> <div id="text" style="position: relative;"> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> here comes shit loads of text <br /> </div> </div> </body> </html>
כעקרון הקוד מאד פשוט אבל נתקלתי בבעיה כשרציתי לבנות מחזוריות של הקוד:
אם אני מנסה לקבל את הגודל:
קוד:
document.getElementById("element").style.height
הוא פשוט מחזיר לי מחרוזת ריקה!
בלי זה, נאלצתי לקבוע גודל מוערך של 350px למחזוריות...
איך אני מטפל בבעיה?
אני לא רוצה לקבוע גודל מוגדר - כי אני רוצה לבנות משהו קצת כללי יותר...
תודה לעוזרים!
_____________________________________
חתימתכם הוסרה כיוון שלא עמדה בחוקי האתר. לפרטים נוספים לחצו כאן. תוכלו לקבל עזרה להתאמת החתימה לחוקים בפורום חתימות וצלמיות.
|