Tengo un programa y funciona bien. Ver HERE.
Este es el código:
<div id="round"></div>
<style>
#round{
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
left: 400px;
top: 200px;
background-color: #e1e1e1;
}
</style>
<script src="jquery.js"></script>
<script src="jquery.easing.1.3.js"></script>
<script>
$(document).ready(function(){
$("#round").click(function(){
setInterval(function(){
$("#round").animate(
{height: 250,
width: 150,
top:150,
left: 425},
{duration: 300}
).
animate(
{height: 200,
width: 200,
top:200,
left: 400},
{duration: 300}
);
}, 0);
});
});
</script>
Pero cuando cambio "#round" a "este". No funcionará ¿por qué? (en realidad funciona, pero cuando me los puse en setInterval(), no va a funcionar) el cambio
$(document).ready(function(){
$("#round").click(function(){
setInterval(function(){
$("#round").animate(
{height: 250,
width: 150,
top:150,
left: 425},
{duration: 300}
).
animate(
{height: 200,
width: 200,
top:200,
left: 400},
{duration: 300}
);
}, 0);
});
});
a "este", no va a funcionar.
$(document).ready(function(){
$("#round").click(function(){
setInterval(function(){
$(this).animate(
{height: 250,
width: 150,
top:150,
left: 425},
{duration: 300}
).
animate(
{height: 200,
width: 200,
top:200,
left: 400},
{duration: 300}
);
}, 0);
});
});
Ver [Javascript _this_ gotchyas] (http://www.sitepoint.com/javascript-this-gotchas /) –
[Más de lo que siempre quiso saber sobre 'esto'] (http://stackoverflow.com/questions/133973/how-does-this-keyword-work-within-a-javascript-object-literal/134149 # 134149) – andyb
@andyb: Es curioso, solo estaba buscando esa publicación ... –