0

そのため、ユーザーの入力に基づいて段階的な手順を動的に生成する erb がいくつかあります。各ステップにはテキストがあり、その上に画像タグが重ねられた少なくとも 1 つの画像があります (ステップの説明テキストが参照しているものを強調表示します)。問題は、現在、画像のサイズが大きすぎてモバイルでの表示に適さないことです。(最大幅は 640px です)。私は各タグの XY 位置を持っているので、命令が読み込まれるときに各タグの周りを動的に切り取って幅を減らしたいと思います (300px で十分だと思います)。これについてどうするのが最善の方法でしょうか?前もって感謝します

jQuery (タグの表示方法)

$('span.i_contact').each(function() {                
    var pos_width = $(this).data('pos-width');
    var pos_height = $(this).data('pos-height');
    var xpos = $(this).data('pos-x');
    var ypos = $(this).data('pos-y');
    var taggedNode = $('<div class="tagged" />')
    taggedNode.css({
        "border":"5px solid orange",
        "width":pos_width,
        "height":pos_height,
        "left":xpos,
        "top":ypos
    });

    var n = $(this).data('index')
    $('.i_tagmap' + n).append(taggedNode)  
    console.log(taggedNode.position())    
});

$("span.o_contact").each(function() {            
    var pos_width = $(this).data('pos-width');
    var pos_height = $(this).data('pos-height');
    var xpos = $(this).data('pos-x');
    var ypos = $(this).data('pos-y');

    var taggedNode = $('<div class="tagged" />')
    taggedNode.css({
        "border":"5px solid green",
        "width":pos_width,
        "height":pos_height,
        "left":xpos,
        "top":ypos  
    });
    var n = $(this).data('index')
    $('.o_tagmap' + n).append(taggedNode)        
});

アーブ:

<% n = steps.index(step) %>
<h2 style="margin-left:20px;"> Step <%= n + 1%></h2>
<div class="stepcontainer">
<div class="steptext">
    <% if step.priority == 1 %>
        <%= "Plug the #{step.i_connection.cord_type.name} end of the cable into the #{step.i_product.full_name}.  Then plug the #{step.o_connection.cord_type.name} end into the #{step.o_product.full_name}." %>
    <% elsif step.priority == 2 %>
        <%= "Plug the #{step.i_connection.cord_type.name} end of the cable into the #{step.i_product.full_name}.  Then plug the #{step.o_connection.cord_type.name} end into the #{step.o_product.full_name}." %>
    <% elsif step.priority == 3 %>
        <%= "Plug the #{step.o_connection.product.full_name } #{step.o_connection.cord_type.name} Cable into the wall." %>
    <% elsif step.priority == 4 %>
        <%= "Plug the #{step.i_connection.cord_type.name} end of the cable into the #{step.i_connection.product.full_name}.  Then plug the #{step.o_connection.cord_type.name} end into the #{step.o_connection.product.full_name}." %>
    <% elsif step.priority == 5 %>
        <%= "Plug #{step.o_connection.product.full_name}" %>
    <% elsif step.priority == 6 %>
        <%= "Touch the #{step.o_connection.button.name} Button on the #{step.o_connection.product.full_name}" %>
    <% end %>
</div>
<div class="modalbutton">
<%= render(step.flags.new) %>   
</div>

<div class="productimg">    
    <span class="o_contact o_contact<%= n %>" data-pos-x="<%= step.o_connection.pos_x %>" data-pos-y="<%= step.o_connection.pos_y %>"  data-pos-width="<%= step.o_connection.pos_width %>" data-pos-height="<%= step.o_connection.pos_height %>" id="spanid<%= n %>" data-index="<%= n %>"> </span>

<% if step.input_contact.present? %>
    <span class="i_contact i_contact<%= n %>" data-pos-x="<%= step.i_connection.pos_x %>" data-pos-y="<%= step.i_connection.pos_y %>"  data-pos-width="<%= step.i_connection.pos_width %>" data-pos-height="<%= step.i_connection.pos_height %>" ="spanid<%= n %>" data-index="<%= n %>"></span>    

    <div id="image_panel<%= n %>" style="float:left; width:300px; position:relative;">
        <%= link_to image_tag(step.i_connection.image.image.url(:medium)), "#{step.i_connection.image.image.url(:large)}", class: "fancybox" %>
        <div class="i_tagmap<%= n %>"></div>
    </div>      
</div>

<div class="cableimg">
    <% if step.i_connection.cord_type.present? %>

            <%= image_tag(step.i_connection.cord_type.image.url(:thumb), :class => "orange")  %>
    <% end %>           
    <% end %>   

    <% if step.o_connection.cord_type.present? %>
            <%= image_tag(step.o_connection.cord_type.image.url(:thumb), :class => "green") %>      
    <% end %>
</div>

<% if step.o_connection.button.present? %>
    <div class="productimg">
        <div id="image_panel<%= n %>" style="float:left; width:300px; position:relative;">
            <%= link_to image_tag(step.o_connection.image.image.url(:medium)), "#{step.o_connection.image.image.url(:large)}", class: "fancybox" %>
            <div class="o_tagmap<%= n %>"></div>
        </div>  
    </div>

<% else %>
    <div class="productimg">
        <div id="image_panel<%= n %>" style="float:left; width:300px; position:relative;">
            <%= link_to image_tag(step.o_connection.image.image.url(:medium)), "#{step.o_connection.image.image.url(:large)}", class: "fancybox" %>
            <div class="o_tagmap<%= n %>"></div>
        </div>  
    </div>              
<% end %>
</div>
<br>
4

2 に答える 2

0

クライアント側で Jcrop を試すことができます。

http://railscasts.com/episodes/182-cropping-images-revised?view=asciicast

またはサーバー側の RMagick:

http://railscasts.com/episodes/374-image-manipulation

于 2013-08-03T15:12:36.740 に答える
0

filepickerioは非常に優れており、エンド ツー エンドのソリューションを探している場合は、画像の後処理機能を提供します。ホームページの最後の例をチェックしてください

于 2013-08-03T16:36:08.073 に答える