(function(){
if (typeof $(".grid") === "undefined") {
return false;
} else {
var count = 0;
var images_to_place_container = ".grid";
for (var image in images_to_place) {
$(images_to_place_container).prepend("<div class = grid-item><div class=grid-item-hover></div><a href=work.php><img src=" + images_to_place[count] + "></a></div>");
count++;
}
}
})();我有一段为站点动态生成图像的代码,现在我想要的是,当我将鼠标悬停在其中一个元素上时,我想动态生成一个div,它的大小和位置与我悬停的动态生成的对象相同。此外,所有元素都是使用CSS进行绝对定位的。谢谢。
发布于 2016-09-14 13:40:06
<body>
<div class='container'>
</div>
</body>
<script>
$(document).ready(function(){
//this dynamically "creates" the images...
$(".container").append("<img src='something.png' class='abc'>");
//this watches for click triggers on dynamically created elements
$(".container").on("click", "img.abc", function(){
var pos_top = $(this).css("top");
var pos_left = $(this).css("left");
var obj = "<div class='def'></div>";
$(obj).css("top", pos_top);
$(obJ).css("left", pos_left);
$(".container").append(obj);
});
});
</script>给abc和def类必要的css规则,比如位置、边距等。
https://stackoverflow.com/questions/39482981
复制相似问题