【发布时间】:2012-12-20 13:36:20
【问题描述】:
我正在尝试创建一个 Greasemonkey 脚本,为每个网页添加一个可拖动的 div。出于某种原因,div 根本没有显示。这可能是什么原因?
// ==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++);
});
});
【问题讨论】:
-
还有另一个脚本可以做到这一点:userscripts.org/scripts/show/47608 我可以使用这个脚本的源代码,这将是一个相当好的解决方法。
-
@Ohgodwhy 我注意到下面的脚本仅适用于少数网站(例如 Stackoverflow.com)。您是否让它在其他网站(例如 google.com 和 jsfiddle.com)上正常工作?
标签: jquery greasemonkey