Why scrollWidth doesn't work in this case in Firefox?

前端 未结 2 1082
轻奢々
轻奢々 2020-12-21 13:50

I\'m trying to make a simple marquee in Javascript, and need to get the full content width of innerDIV in the following:

相关标签:
2条回答
  • 2020-12-21 14:30

    This seems to do the trick:

    docWidth = Math.max(
            Math.max(frameDoc.body.scrollWidth, frameDoc.documentElement.scrollWidth),
            Math.max(frameDoc.body.offsetWidth, frameDoc.documentElement.offsetWidth)                               
    );
    
    0 讨论(0)
  • 2020-12-21 14:37

    I had the same issue and I found an answer for your questions. This is a bug in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=833542.

    Firefox returns for scrollWidth the clientWidth value. It should be fixed in Firefox 21.

    For now, I used a workaround to get the correct scrollWidth on Firefox: set the overflow to hidden, get the correct scrollWidth and revert the overflow to visible. Please see: http://jsfiddle.net/5fPGy/5/

    var scrollWidth = $(ele).css("overflow", "hidden")[0].scrollWidth;
    alert('clientWidt h = ' + ele.clientWidth + ',  scrollWidth = ' + scrollWidth  );
    $(ele).css("overflow", "visible");
    

    Best of luck,

    Andrei

    0 讨论(0)
提交回复
热议问题