本萌新写了一段代码,但是死活不执行,求各位大神不吝赐教,谢谢!
$("#floating").click(function(){
$("#floating").animate({
width : '213px',
height : '585px',
marginLeft : '900px',
backgroundImage : 'url(source/caihong.png)'
},"slow");
});
#floating{
float : none;
z-index : 2;
position : fixed;
width : 100px;
height : 100px;
margin-left : 1100px;
}
<div id = "floating" ><img src = "source/jixiangwu.png" width = 100px height = 100px></div>
在下感激不尽!
$(document).ready(function(){
$("#floating").click(function(){
$("#floating").animate({
width : '213px',
height : '585px',
marginLeft : '900px',
backgroundImage : 'url(source/caihong.png)'
},"slow");
});
});
jQuery进行DOM操作时,需要加上$(document).ready(function(){});
意思是等待DOM文档树加载完成后执行。
把DIV放到JS代码前,或者像楼上说的,放到$(document).ready(function(){执行的代码});里面再试试。