相关疑难解决方法(0)

jQuery回调图像加载(即使图像被缓存)

我想要做:

$("img").bind('load', function() {
  // do stuff
});
Run Code Online (Sandbox Code Playgroud)

但是从缓存加载图像时不会触发加载事件.jQuery文档提出了一个修复此问题的插件,但它不起作用

jquery image jquery-load jquery-events

282
推荐指数
8
解决办法
36万
查看次数

使用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 ×2

jquery ×2

javascript ×1

jquery-events ×1

jquery-load ×1