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