Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 12-11-2012, 01:33 PM
Snakehill Snakehill is offline
 
Join Date: Feb 2010
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default vBulletin Javascript issue in IE

This is a piece of code I created as a cross-brower/cross-platform solution for fixing/locking a div on a custom vB page (so that it scrolls along with the page scrolling). However, when adding it, it works in all browsers but IE. Unlike the other ones, Internet Explorer cannot seem to get hold of any of the values requested by the code, and required for it to work well. Other functions still work, it is just not getting the offsetTop and window.pageYOffset values.

However, when trying this outside of a vB page, it works great, even on IE, so something from vB seems to be conflicting and I have no idea what it is or how to make it work along with this code.

Code:
<script type="text/javascript">
window.onscroll = function (e) {
var basediv = document.getElementById('basediv').offsetTop;
var setdiv = document.getElementById('setdiv');
 if (window.pageYOffset	< (basediv - 1)) {
 setdiv.style.top = "0px";
 } 
 else {
 setdiv.style.top = (1 + (window.pageYOffset - basediv) + "px");
 }
}
</script>
The offsetTop and window.pageYOffset for some reason always return 0 and undefined. I have tried adding the code anywhere on the page, in between the head tags, and in an external js file, but nothing worked.

The following I have used to test it:

Code:
<script type="text/javascript">
window.onscroll = function (e) {
var testdiv = document.getElementById('testdiv').offsetTop;
alert(window.pageYOffset + " " + testdiv);
}
</script>

<div id="testdiv"></div>
Again, it works fine on its own but as soon as it is placed on a custom vB page, something stops it from getting the requested values.

Help is very much appreciated! Thanks!
Reply With Quote
  #2  
Old 12-11-2012, 04:45 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm really a js beginner so I don't know what's going on, but you only have to google "getElementById in ie" to find that it has issues. One suggestion I found was to get all elements of a given tag name and check the id yourself, something like

Code:
function myGetElementById(tag, id)
{
   var elements = document.getElementsByTagName( tag );
    for var i = 0; i < elements.length; ++i )
    {
        if( elements[i].id == id )
        {
            return elements[i];
        }
    }
    return null;
}
 ...

var basediv = myGetElementById('div', 'basediv').offsetTop;

(I haven't tried this code at all so it could have typos or other problems, but you get the idea).
Reply With Quote
  #3  
Old 12-11-2012, 05:20 PM
Snakehill Snakehill is offline
 
Join Date: Feb 2010
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nah, the flaw definitely is not in the getElementById, unfortunately.

Let me show you an example. This is on vB:
Link has been removed

Scroll to get to see the bunch of alerts with the requested values. The first value is the window.pageYOffset (not ID-related, flexible value), the second is using the offsetTop (ID-related, fixed value). In every browser but IE you see two values of numbers above 0. In Internet Explorer either only one or none show up (undefined/0).

This is the exact same code but outside of vB, and you will see it all works fine:
Link has been removed
Reply With Quote
  #4  
Old 12-11-2012, 08:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

oh, ok. Then maybe this: http://stackoverflow.com/questions/1...imation-in-ie8

I know this doesn't really explain why it works outside of vb.
Reply With Quote
  #5  
Old 12-12-2012, 11:28 AM
Snakehill Snakehill is offline
 
Join Date: Feb 2010
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
oh, ok. Then maybe this: http://stackoverflow.com/questions/1...imation-in-ie8

I know this doesn't really explain why it works outside of vb.
No luck. Thanks a lot for trying to help though.

I ended up adding getBoundingClientRect for whichever browser and device supports that instead of the above code. Works like a charm and no conflicting with vB so we're all good.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:19 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07173 seconds
  • Memory Usage 2,194KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete