小编800*_*00i的帖子

在ember中的图像标记上使用Onload

我有一个模板,其中照片显示在一个框架中(每个框架对于不同的图像是不同的).我已经编写了一个功能,使用图像原始的高度和宽度,并给我自定义的宽度和高度为该特定框架,以便恢复宽高比.现在我通过onload调用该函数,因为图像在特定时刻加载.

我的feed.hbs(模板)

<img src = "{{photo.0.photo_url}}" onload = "OnImageLoad(event);" {{action "imgOverlay0" photo}}/>
Run Code Online (Sandbox Code Playgroud)

功能

function OnImageLoad(evt) {

    var img = evt.currentTarget;

    // what's the size of this image and it's parent
    var w = $(img).width();
    var h = $(img).height();
    var tw = $(img).parent().width();
    var th = $(img).parent().height();

    // compute the new size and offsets
    var result = scaling(w, h, tw, th,false);

    // adjust the image coordinates and size
    img.width = result.width;
    img.height = result.height;
    $(img).css("margin-left", result.targetleft);
    $(img).css("margin-top", result.targettop);
    // console.log("result",result)
    return …
Run Code Online (Sandbox Code Playgroud)

javascript ember.js ecmascript-6

2
推荐指数
1
解决办法
1133
查看次数

标签 统计

ecmascript-6 ×1

ember.js ×1

javascript ×1