DIVS
(動的に追加された関数を使用して)いくつかを動的に追加しようとしていCONTAINER
ます。これらの誰かをクリックするとDIVs
、MENU
これに挿入されますDIV
。で私はこれから または約5秒で削除mouseleave
する必要があります。それは動作しますが、無秩序に...だから私は必要です:MENU
DIV
delay
setInterval
mouseleave
これから出てDIV
すぐにマウスをこれの上に戻すと、DIV
停止する必要がありdelay
ますsetInterval
。の削除を停止する必要がありMENU
ます。関数に問題があります
'handler'
。DIV
にいくつかを追加するときCONTAINER
、初めてdoubleclik
この関数を呼び出すためにを使用する必要があるためです。しかし、私は単純なクリックを使用する必要があります。
次に例を示します:http: //jsfiddle.net/ynternet/84nVQ/5/
HTML
<div id="add" style="background:yellow; width:100px;"> add new </div>
<div id="container"> </div>
<div id="menu" style="color:red;"><b> I'm here </b></div>
jQuery
function handler() {
$(this).on({
click: function(e) {
clearTimeout(time);
if ($(this).find("#menu").length) {
return;
}
$('#menu').prependTo($(this));
$("#menu").css({
position: "absolute",
left: "100px"
}).show();
}
});
$(this).on({
mouseleave: function(e) {
time = setTimeout(function() {
$('#menu').appendTo('body').clearTimeout(time);;
}, 5000);
}
});
$(this).on({
mouseover: function(e) {
clearTimeout(time);
}
});
}
$("#add").on({
click: function(e) {
var timestamp = Date.now();
var posx = Math.floor(Math.random()*400);
var posy = Math.floor(Math.random()*400);
$('#container').append(function() {
return $('<div class="add_to_this" id="' + timestamp + '" style="left:'+posx+'px; top:'+posy+'px; ">Click here</div>').click(handler);
});
}
});
CSS
#container {
width:500px;
height:500px;
background: palegoldenrod;
position: relative;
top:20px;
left: 100px;
padding: 0px;
}
.add_to_this {
background:yellowgreen;
position: absolute;
display:inline-block;
width:200px;
height:30px;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
-o-user-select: none;
}