jQuery .append() in Firefox: vertical scrollbar appears? -


i want dynamically add number of divs target div in page .append(), set heights , positions they're visible in page without scrolling.

all of goes ok, in firefox (3.6.16 on ubuntu) vertical scrollbar appears, though height of each new div being added total height of page content - though each new div near top of screen, , height isn't anywhere near length of screen. ubuntu chrome behaves fine. when ask jquery height of target div after appending new divs, hasn't changed.

here's of page code test page wrote isolate problem - in advance!

        <style type="text/css">         #target {             width: 50px;             height: 50px;             background-color: #cfc;         }     </style>     <script>         $(document).ready(function() {             var cols = new array('#660', '#606', '#066', '#993', '#939', '#399', '#cc9', '#c9c', '#9cc', '#ffc', '#fcf', '#cff');              for(i = 0; < 10; i++){                 $('#target').append('<div id="new_' + + '">hello</div>');                 $('#new_' + i)                 .position({                     my: 'left top',                     at: 'left top',                     of: '#target',                     offset: '' + (i * 20) + ' ' + (i * 10)                 })                 .width(200)                 .height(150)                 .css('background-color', cols[i]);             }         });     </script> </head> <body>     <div id="target">     </div> </body> 

if give added <div> elements "position: absolute", you'll no scrollbars.

the jquery ui ".position()" utility give affected elements (your added <div> elements) "position: relative" if they're not otherwise set "position". elements positioned way consume layout space on page if not moved away "natural" position. thus, page overflows when add elements though they're relocated such fit.

by giving them "position: absolute", take them out of ordinary layout flow. chrome doesn't agree this, reasons don't understand; think firefox doing correct thing here. (edit — if add line append 1 last <div> "target", , make plain-jane <div> little text in no positioning @ all, you'll see ends way way down page in chrome, , scrollbar same size firefox gives you. thus, looks chrome doesn't "claim" phantom space unless comes after it.)

here jsfiddle. updated code (one line):

    $(document).ready(function() {         var cols = new array('#660', '#606', '#066', '#993', '#939', '#399', '#cc9', '#c9c', '#9cc', '#ffc', '#fcf', '#cff');          for(i = 0; < 10; i++){             $('#target').append('<div id="new_' + + '">hello</div>');             $('#new_' + i)             .position({                 my: 'left top',                 at: 'left top',                 of: '#target',                 offset: '' + (i * 20) + ' ' + (i * 10)             })             .css('position', 'absolute')             .width(200)             .height(150)             .css('background-color', cols[i]);         }     }); 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -