小编the*_*and的帖子

使用jQuery加载图像并将其附加到DOM

我正在尝试从给定的链接加载图像

var imgPath = $(imgLink).attr('href');

并将其附加到页面,因此我可以将其插入到图像查看器的给定元素中.即使我搜索StackoverflowjQuery文档没有结束,我无法弄明白.

加载图像后,我想为它设置不同的值,如宽度,高度等.

更新:

这就是我得到的.我遇到的问题是我无法在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)

javascript jquery image

38
推荐指数
5
解决办法
14万
查看次数

标签 统计

image ×1

javascript ×1

jquery ×1