4
Oops, I’m not getting the height of an object in the document.
I have a slider, which works with ul > li
(may be relevant), and inside a slide <li>
, I am placing via javascript and c# three Divs, each with an image inside.
What I need to do is recall the time the image was rendered. I have tried several ways to access, but it seems that javascript can not collect the data at runtime...
I’ve tried to:
$("foo").height();
$("foo").naturalHeight(); // nesse caso eu teria uma solução "budget" para o caso
$("foo").outerHeight();
After storing the data, I need to set in another div according to the found result.
$("#noticias").css("height", fullHeight);
I have also tried to give a timeout after feeding the Divs created by c#, but also did not solve. The question is: Is there anything that helps me collect data at runtime? Between js and jQuery?
I appreciate any suggestion.
Can you add an example in jsFiddle? what you experienced is correct, I don’t notice what might be failing.
– Sergio
Very complicated, besides the data come from c#, as mentioned, I’m using bootstrap and more the slider plugin...
– William de Castro
Do you have a live link? If it’s not going to be difficult... have you tried with
element.offsetHeight
orelement.getBouningClientRect().height
or evenwindow.getComputedStyle(element).height
?– Sergio
None of these, I will test these here, worst of all on local server :/ Already put the test result.
– William de Castro
Log the height of the image into the console. See if you are returning the value. Do this with height(). In case it does not return anything the problem is in the identification of the element. As @Rgio said it is kind of complicated to help the blind so.
– Diego Henrique
We did some experiments and it was clear that the problem is in the running time. I tested with a Sleep of 500 and it worked.
– William de Castro
In this case try using a recursive setInterval or setTimeout, which checks whether the value is a valid value according to its rules. Another solution is to create an Eventlistener and trigger this C#event. Or even use something generic like when the page is loaded
$(document).ready(function(){ //code });
– Pedro Henrique
This question seems to be decontextualized because the problem is not clear and it is not possible to reproduce.
– Sergio
Make an example in Fiddle that represents your already rendered HTML.
– Oralista de Sistemas
If I understand correctly, you have several images of heights distinct. When changing the image in the slider, you want the slider acquire the current image height, correct?
– Kazzkiq