问题
I'm getting wrong values from jquery .offset(), I think it is because of CSS but cannot find the error.
This is the HTML element I'm trying to get the offset of:
<div id="sedes" class="seccion_in">
</div>
This is the CSS
.seccion_in { position:relative; overflow: hidden; width: 100%; height: auto; }
And this is the jquery:
console.log($("#sedes").offset());
And this is the working link: http://ficm.hacemoscodigo.com/asiste/
Thanks for your help.
回答1:
IDs MUST BE UNIQUE!
You have #sedes located in <div id="nav"> as well as a #sedes in <div id="content">. My guess is you are getting the .offset() of the #sedes in your nav. Remove/rename the ID that element and you should be good.
Make sure to use a classes instead.
Let me know if you have any questions!
回答2:
Review the jQuery API for offset.
It should be returning {top: 0, left: 0} because of the positioning of the parent.
来源:https://stackoverflow.com/questions/16092512/getting-wrong-values-from-jquery-offset