Jquery 在其他图像上方显示图像
我有一个背景图像,我想执行的功能是,当点击一个按钮时,第二个图像会添加到背景图像上方。图像是通过在我的代码中单击添加的,但不在背景图像上方。此外,我的图像可以拖动,如果我提到Jquery 在其他图像上方显示图像,jquery,jquery-ui,css,Jquery,Jquery Ui,Css,我有一个背景图像,我想执行的功能是,当点击一个按钮时,第二个图像会添加到背景图像上方。图像是通过在我的代码中单击添加的,但不在背景图像上方。此外,我的图像可以拖动,如果我提到width和height 为了更好地解释,代码如下: $(文档).ready(函数(){ $(“按钮”)。单击(函数(){ $(“#当前图像”)。在(“”)之后; $(“#可拖动”).draggable() }); }); $(文档).ready(函数(){ $(“按钮”)。单击(函数(){ $(“#current
width
和height
为了更好地解释,代码如下:
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$(“#当前图像”)。在(“”)之后;
$(“#可拖动”).draggable()
});
});
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$(“#currentimage”)。附录(“”);
$(“#可拖动”).draggable()
});
});
您可以使用.appendTo()
试试这个:
html:
单击图像时,它将获取当前图像偏移并覆盖下一图像。尝试以下操作:
$(document).ready(function(){
$("button").click(function(){
$("#currentimage").html('<img id="dragable" src="http://s25.postimg.org/pi8ruls3z/image.jpg" width="200px" height="auto" />'+"<br /><img src=\"http://s25.postimg.org/v554s2umn/man_looking_at_sunset.jpg\" width=\"200px\" style=\"height: auto; z-index: 0;\"/>");
$("#dragable").draggable()
});
});
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$(“#currentimage”).html(“+”
);
$(“#可拖动”).draggable()
});
});
stmthanks Arun之后改为之前的用户这正是我想要的。请告诉我当我第二次单击“添加图像”时会发生什么。第二个实例不再可拖动
$(document).ready(function(){
$("button").click(function(){
$("#currentimage").appendTo('<img id="dragable" src="http://s25.postimg.org/pi8ruls3z/image.jpg" width="200px" height="auto" />');
$("#dragable").draggable()
});
});
<div id="draggable" style="display:none;">
<img src="http://s25.postimg.org/pi8ruls3z/image.jpg" width="200px" height="auto" />
</div>
$(document).ready(function(){
$("button").click(function(){
var position = $("#currentimage").offset();
height = $("#currentimage" ).height();
//width = $("#currentimage" ).width();
$("#dragable").css({ "display" : "block" , 'height':height, position : "absolute", "z-index" :"101", "background-color" : "#009ddf","opacity" : "0.9" } );
$("#dragable").offset($("#currentimage" ).offset());
$("#dragable").draggable();
});
});
$(document).ready(function(){
$("button").click(function(){
$("#currentimage").html('<img id="dragable" src="http://s25.postimg.org/pi8ruls3z/image.jpg" width="200px" height="auto" />'+"<br /><img src=\"http://s25.postimg.org/v554s2umn/man_looking_at_sunset.jpg\" width=\"200px\" style=\"height: auto; z-index: 0;\"/>");
$("#dragable").draggable()
});
});