2011-09-11 17 views
57

Bölme kullanımı css taşmasının scrollHeight'ını nasıl belirlerim: auto?scrollHeight'ı nasıl belirlerim?

denedim:

$('test').scrollHeight(); 
$('test').height(); but that just returns the size of the div not all the content 

Sonuçta, ben bir sohbet oluşturmak çalışıyorum ve her zaman ekranda geçerli iletiye kaydırma çubuğunu var.

Yani aşağıdaki gibi bir şey düşünüyordum:
var test = $('test').height(); 
$('test').scrollTop(test); 

Teşekkür ederim,

Brian jQuery gerekmez

+0

scrollHeight() kullanılarak sorun nedir? –

+2

@BadrHari: jQuery'de 'scrollHeight()' işlevi yoktur. –

+0

$ ('test'). Olsun (0) .scrollHeight(); – JFouad

cevap

57

scrollHeight düzenli javascript özelliktir. jQuery

var test = document.getElementById("foo").scrollHeight; 
+0

Teşekkürler! Bu benim için çalıştı: var height = document.getElementById ("chatLog") scrollHeight - $ ('# chatLog'). Height(); \t \t $ ('# chatLog') scrollTop (yükseklik); – Brian

+6

Tarayıcı desteği nedir? Tüm büyük tarayıcı sürümleri bunu destekliyor mu? IE8 +? – SexyBeast

+1

@Cupidvogel Bağlantılı MDN sayfası, orjinal jQuery kullanıyorsa, $ (0 # test ') [0] .scrollHeight için IE8 + – Dennis

212

Doğru yolu vardır -

  • $('#test').prop('scrollHeight') VEYA
  • $('#test')[0].scrollHeight

yardımcı olur Umut.

+10

+1 diyor. – Jackson

+9

Bu, soruya cevap verdiğinden kabul edilen yanıt olmalıdır. – invot

+0

Kabul edilen cevap olmalı. 'Prop' yönteminin jquery sürüm 1.6 veya daha büyük olmasını gerektirdiğine dikkat edin. +1 benden – Vayne

İlgili konular