Pass img src via jquery to new div
I am trying to create a "simple" modal type of operation. When a user clicks on an image it opens a mask over the screen (done that) and displays the image (can't do that). This is ment to be very simple, no need for galleries etc. hence just a simple effect.
The code generated for the mask is
$j(document).ready(function(){
$j('.postentry img').click(function(e) {
e.preventDefault();
var maskHeight = $j(document).height();
var maskWidth = $j(window).width();
$j('#mask').css({'width':maskWidth,'height':maskHeight});
$j('#mask').fadeIn(1000);
$j('#mask').fadeTo("slow",0.8);
});
});
I can get the src of the image (but just forgotten the code) but it's abit like this
Sj('postentry img').att(src)
(Or something I did开发者_运维知识库 get it to dispaly properly in an alert but how do I pass that sc to a hidden div and display it above the mask (OK I assume that's z-index in the css) but it's more how do I display the image.
Help please Thanks
You need to do
$('.postentry img').attr('src', 'imageurl').show();
or just
$('.postentry img').attr('src', 'imageurl');
and then show the div containing the image using
$('#imagediv').show();
If you show your html I could give a definite answer. Also, the you don't need to put the j after $.
Its
$j('postentry img').attr(src)
See .attr()
and to show the image you can call the .show() method
$j('postentry img').attr('src', yourimageurl).show();
See .show()
精彩评论