如何显示原始图像大小

时间:2018-02-23 13:00:08

标签: javascript css height

//Shows automatically the width and height from images
                $(document).ready(function () {
                    //Select all the images on the page
                    var img = $("#resultsFromSearch3").find('.oa-panels-col-33').find('img');
                    //For every image the code below will run 
                    $(img).each(function() {
                        //The code below select the p that belongs to the image. 
                        var description = $(this).closest('.oa-panels-row').find('.views-field-file-field-oa-body-value .field-content p:last-child');
                        //Create a new img element with the src of the orinial image. 
                        $("<img>").attr("src",$(this).attr('src')).load(function () {
                            //Print the width and height, of this clone image, in the description of the orinial image. 
                            description.after('<b>'+'Width=' + '</b>' +  this.width + 'px '+ '<br>' + '<b>'+'Height='+'</b>'+  this.height + 'px' + '<br>');
                        });
                    });
                });

我想在列表中的屏幕上显示原始图像大小。现在它显示缩略图的宽度和高度。有人熟悉吗?

1 个答案:

答案 0 :(得分:0)

从这一点开始,从我能看到的内容中我可以看到,我可以看到你的Chrome Dev工具控制台可能会出现错误,说明$未定义。除非我弄错了(你可能有一个Js文件并且已经将$定义为Jquery)但你可能要写:

<rewrite> 
        <rules> 
            <rule name="Route the requests for WFL" stopProcessing="true"> 
                <match url="extFlow/(.*)" /> 
                <conditions> 
                </conditions> 
                <action type="Rewrite" url="https://site2/extFlow/{R:1}" logRewrittenUrl="true" />
                <serverVariables>
                    <set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}" />
                    <set name="HTTP_ACCEPT_ENCODING" value="" />
                </serverVariables> 
        </rules> 
        <outboundRules> 
            <rule name="ReverseProxyOutboundRule1" preCondition="NeedsResportingAcceptResp" stopProcessing="true"> 
                <match filterByTags="A" serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)" /> 
                <action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" /> 
            </rule> 
            <preConditions> 
                <preCondition name="NeedsResportingAcceptResp">
                    <add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+" />
                </preCondition> 
            </preConditions> 
        </outboundRules> 
</rewrite>  

<handlers>
        <remove name="svc-ISAPI-4.0_64bit" />
        <remove name="svc-ISAPI-4.0_32bit" />
        <remove name="svc-Integrated-4.0" />
</handlers>

从这里你可以看到我只在document.ready函数中添加了$,但就像我说你可能已经在文件中的其他地方定义了(在显示的内容之上),但如果没有,这可能会解决你的问题。< / p>