我正在尝试从给定的链接加载图像
var imgPath = $(imgLink).attr('href');
并将其附加到页面,因此我可以将其插入到图像查看器的给定元素中.即使我搜索Stackoverflow和jQuery文档没有结束,我无法弄明白.
加载图像后,我想为它设置不同的值,如宽度,高度等.
更新:
这就是我得到的.我遇到的问题是我无法在img
元素上运行jQuery函数.
function imagePostition(imgLink) {
// Load the image we want to display from the given <a> link
// Load the image path form the link
var imgPath = $(imgLink).attr('href');
// Add image to html
$('<img src="'+ imgPath +'" class="original">').load(function() {
$(imgLink).append(this);
var img = this;
// Resize the image to the window width
// http://stackoverflow.com/questions/1143517/jquery-resizing-image
var maxWidth = $(window).width(); // …
Run Code Online (Sandbox Code Playgroud)