简体   繁体   English

如何通过调平动态改变宽度和高度

[英]How to change width and height dynamically with leveling

I have faced some problems. 我遇到了一些问题。 When I write text on a input field, writing text show another text filed. 当我在输入字段上写文本时,写文本显示另一个文本。 Another text field width and height not changing dynamically with leveling like below image and demo site 另一个文本字段宽度和高度不会随着图像和演示站点下方的水平而动态变化

My Demo Site 我的演示网站

Default width and height 默认宽度和高度

默认宽度高度

不改变水平,高度和宽度

输入字段

But I want like this desired output Desired Output Link 但我想要这个所需的输出Desired Output Link

期望的输出

期望的输出

For desired output input like these and Demo Site 对于像这些和Demo Site这样的所需输出输入

输入

I have faced another problem height is shown upper of the box. 我面临另一个问题,高度显示在盒子的上方。 But the height should show left or right position of the box. 但高度应显示框的左侧或右侧位置。

Inner hole of the box is another problem that i don't include my box. 盒子的内孔是另一个问题,我不包括我的盒子。

And last problem is don't add leveling end arrow of the leveling line. 最后一个问题是不要添加调平线的水平结束箭头。 My code is below 我的代码如下

For input text 用于输入文本

<div class="text_input1">
    <p class="label1"> Text 1 <input class="input_box1" type="text" id="text11" name="text11" value="Enter Text1"></p>
</div>

 <div class="text_input1">
<p class="label1"> Text 2 <input class="input_box1" type="text" id="text22" name="text22" value="Enter Text2"></p>
</div>

<div class="text_input1">
<p class="label1"> Text 3 <input class="input_box1" type="text" id="text33" name="text33" value="Enter Text3"></p>
</div>

For width and height Select 对于宽度和高度选择

</div>

<h2 class="shape_text_width">WIDTH:</h2>
<div class="iteam_icon2">

<input type="text" id="width" name="width" value="79" onchange="XX()"><p class="mili1">mm</p</input>

</div>
<h2 class="shape_text_width">HEIGHT:</h2>
<div class="iteam_icon2">

    <input type="text" id="height" name="height" value="26" onchange="XX1()"><p class="mili1">mm</p></input>

</div>

Change width and height 改变宽度和高度

$( "#width_label" ).text(79 + " mm");
$("#height_label" ).text( 26 + " mm");

function XX()
{
    var first2 =document.getElementById("width").value;
      var width=first2;
      var width_in_px=width*3.779527559;
      var total_width = Math.round(width_in_px);
      var f_width_in_px = parseInt(total_width);

      var mm_text="mm";

      $('#mySVG1').css("width", f_width_in_px + "px");
      $('#shape1').css("width", f_width_in_px + "px");
      $( "#width_label" ).text( width + " mm");
      $('#width_label').css("width", f_width_in_px + "px");

      var dif=width-300;
      if(width>300)
      {
      $('#height_label').css("margin-right", dif + "px");
      }

} 

 function XX1()
{
    var first22 =document.getElementById("height").value;


      var height=first22;
      var height_in_px=height*3.779527559;
      var total_height = Math.round(height_in_px);
      var f_height_in_px = parseInt(total_height);

      $('#mySVG1').css("height", f_height_in_px + "px");
      $('#shape1').css("height", f_height_in_px + "px");
      $("#height_label" ).text( height + " mm");
      $('#height_label').css("width", f_height_in_px + "px");

}

My OutPut field box width, height and output text code is below 我的OutPut字段框宽度,高度和输出文本代码如下

<div class="label_fix" id="height_label" style="border-bottom: 1px solid #000;
   width:100px;
   margin: 0 auto;
   margin-bottom: 5px;
   padding: 2px;">
</div>

<svg  style="width:300px;height:100px" id="mySVG1">
     <rect id="shape1" x="0" y="0" style="width:300px;height:100px" stroke="black" stroke-width="1px" fill="white"/>
     <<text id="text1" x="50%" y="25%" alignment-baseline="central" text-anchor="middle" fill="black"></text> 
     <<text id="text2" x="50%" y="50%" alignment-baseline="central" text-anchor="middle" fill="black"></text> 
     <<text id="text3" x="50%" y="75%" alignment-baseline="central" text-anchor="middle" fill="black"></text> 

</svg>

<div class="label_fix" id="width_label" style="border-top: 1px solid #000;
   width: 300px;
   margin: 0 auto;
   margin-top: 5px;
   padding: 2px;">
</div>

Value Add to my output field 值添加到我的输出字段

<script>
$( "#text11" )
  .keyup(function(test1) {
    var value = $( this ).val();
    $( "#text1" ).text( value );
    $( "#text_second_1" ).text( value );
    $( "#text_third_1" ).text( value );

  })
</script>
<script>
$( "#text22" )
  .keyup(function(test2) {
    var value = $( this ).val();
    $( "#text2" ).text( value );
    $( "#text_second_2" ).text( value );
    $( "#text_third_2" ).text( value );

  })
</script>
<script>
$( "#text33" )
  .keyup(function(test3) {
    var value = $( this ).val();
    $( "#text3" ).text( value );
    $( "#text_second_3" ).text( value );
    $( "#text_third_3" ).text( value );

  })
</script>

Based on your comment remark above, here is what you are looking after in pure css. 根据您上面的评论评论,这里是您在纯CSS中所关注的内容。 Since the one you asked for required the image to be in mm, I tried to keep the correct ratio using px, however, it is up to you to adjust values as you see fit to get the produced results. 由于您要求的图像要求图像为mm,我尝试使用px保持正确的比例,但是,您可以根据需要调整值以获得生成的结果。

All you need is a div and the following style. 您只需要一个div和以下风格。 To fake the 'holes' I applied a background color to the body and used the same color to color the :before and :after pseudo elements. 为了伪造“洞”,我将一种背景颜色应用于身体,并使用相同的颜色为:before:after伪元素着色。

body {
  background:#ccc;
}
.box {
  box-sizing:border-box;
  background:#fff;
  width:99px;
  border-radius:5px;
  text-align:center;
  padding:7px 0;
  position:relative;
  border:1px solid #000;
  font-size:14px;
}
.box:before,
.box:after{
  content:"";
  position:absolute;
  left:5px;
  display:block;
  width:8px;
  height:8px;
  background:#ccc;
  border-radius:50%;
  top:50%;
  margin-top:-5px;
  border:1px solid #000;
}
.box:after {
  left:auto;
  right:5px;
}

Here is a working fiddle. 这是一个工作小提琴。 https://jsfiddle.net/s6r6frgx/2/ https://jsfiddle.net/s6r6frgx/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM