我正在嘗試創建一個Greasemonkey腳本,它爲每個網頁添加一個可拖動的div。出於某種原因,div完全不顯示。這可能是什麼原因?使用Greasemonkey將可拖動的窗口添加到頁面
// ==UserScript==
// @name Draggable box demo
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match *://www.*
// @copyright 2012+, You
// @require http://code.jquery.com/jquery-latest.js http://code.jquery.com/ui/1.9.2/jquery-ui.js
// ==/UserScript==
//alert("Hi!");
$(document).ready(function() {
$(document).append("<div id='dragZone'><div class='draggable'>Drag here!<input type = 'text'></input></div>");
$('#dragZone').css('position', 'absolute');
var a = 3;
$('.draggable').draggable({
start: function(event, ui) { $(this).css("z-index", a++); }
});
$('#dragZone div').mousedown(function() {
$(this).addClass('top').removeClass('bottom');
$(this).siblings().removeClass('top').addClass('bottom');
$(this).css("z-index", a++);
});
});
還有另外一個腳本,做這樣的:https://userscripts.org/scripts/show/47608我可以使用這個腳本的源代碼,這將是一個相當不錯的解決方法。 –
@Ohgodwhy我注意到下面的腳本只適用於幾個網站(比如Stackoverflow.com)。你是否能在其他網站(如google.com和jsfiddle.com)上正常運行? –