2014-03-06 39 views
0

我想在一個使用擴展的已加載頁面的所有元素上創建一個可拖動的div。我已經注入了jquery腳本和以下代碼。這是我的js文件(從http://coursesweb.net/jquery/jquery-ui-draggable-drag複製)用注入的jquery腳本創建一個可拖動的div

$("body").append('<div id="dg2">hello world</div>'); 
$('#dg2').draggable({ 
    cursor: 'pointer',  // sets the cursor apperance 
    opacity: 0.35,   // opacity fo the element while it's dragged 
    stack: $('#dg2'),  // brings the '#dg1' item to front 
}); 

這是在CSS文件

#dg2 { 
    width:180px; 
    height:100px; 
    margin:8px; 
    top:150px; 
    z-index:1000; 
    background:#a7daa8; 
} 

我看到的div在頁面底部創建。它不能拖拽和移動。 如何在中間創建它並使其能夠移動?請幫忙。

+2

http://jsfiddle.net/anandnat/aBRt5/ –

+0

哎呀。然後在注入jquery-ui時出錯。謝謝。非常感謝。 。 。:D – Charls

回答

1

它工作正常..可能你沒有包括jquery ui腳本標記在你的html中 請確認。

<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 

看到這個工作環節

JSFIDDLE

+0

雅是那個確切的原因。謝謝 – Charls

相關問題