function hitQBlock(obj) {
var objOne=$(obj),
posOne = objOne.offset(),
posVert = posOne.top + (objOne.height()/2),
posHoriz = posOne.left + (objOne.width()/2);
var newCoin = document.createElement('.coin');
newCoin.attr({
style: 'position: absolute; top: posVert px; left: posHoriz px; width: 500px; height: 500px;',
src: 'http://png-3.findicons.com/files/icons/2297/super_mario/256/retro_coin.png'});
}
第一个问题:我怎样才能在newCoin
对象位置由变量posVert
和posHoriz
定义的位置?我试图使用.val()
方法,但它似乎并没有内部报价创建IMG使用jQuery具有可变的位置
第二个问题:什么是更好的方式,使在函数中的自定义类的新对象?我的方式,发现上面,不正确工作。
在添加值之前关闭字符串.... 'style:'position:absolute;顶部:'+ posVert +'px; left:'+ posHoriz +'px;宽度:500px; “高度:500px;'' – Archer 2013-03-08 17:40:32
谢谢,我应该想到xD – 2013-03-08 17:44:34