jquery - 向 iframe 添加高度会使调整大小变得不稳定

标签 jquery css

我正在制作自己的代码 Playground ,类似于codepen。我并不是想做出什么特别的东西,只是想学习如何制作。

从左向右拖动垂直条以调整列大小时遇到​​问题。一旦我在渲染代码的 iframe 上设置了高度,调整大小就会变得跳跃且缓慢。没有高度,它是平滑的。

如何为 iframe 添加高度并保持大小调整顺利?

我正在使用jquery-resizable.js来调整大小。

这是我网站的链接:Code Playground

$(document).ready(function(){
$(".left-column").resizable({
   handleSelector: ".splitter",
   resizeHeight: false
 });

 $(".code-container").resizable({
   handleSelector: ".splitter-horizontal",
   resizeWidth: false
 });

 $(".code-container-2").resizable({
   handleSelector: ".splitter-horizontal-2",
   resizeWidth: false
 });
 $(".code-container-3").resizable({
   handleSelector: ".splitter-horizontal-3",
   resizeWidth: false
 });
 
   });
@import url('https://fonts.googleapis.com/css?family=Fjalla+One');

body {
  background-color: #343436;
  margin: 0;
  padding: 0;
}
.title {
  color: #CDD3DE;
  margin-left: 20px; 
  font-family: 'Fjalla One', sans-serif;
}

#main {
  display: flex;
  flex-direction: row;
  overflow: hidden;
  xtouch-action: none;
}

/*LEFT COLUMN*/
#left {
  flex: 0 0 auto;
  height: calc(100vh - 82.88px);

}
/*stretch makes the div containing the textarea expand the full height*/
.stretch {
  height: 33%; 
  overflow: hidden;
}

textarea {
  height: 100%;
  width: 100%;
  background: #1B2B34;
  font-family: Courier, sans-serif;
  font-size: 14px;
  color: #CDD3DE;
  overflow-y: scroll;
  overflow-x: hidden;
}

/*style the textarea scrollbars*/
textarea::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
  border-radius: 10px;
  background-color: #F5F5F5;
}
textarea::-webkit-scrollbar {
  width: 12px;
  background-color: #F5F5F5;
}
textarea::-webkit-scrollbar-thumb {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
  background-color: #555;
}

/*the dragger for the textareas in left column*/
.splitter-horizontal {
  flex: 0 0 auto;
  height: 18px;
  background: url(https://williamcunningham.me/codebox/hsizegrip.png) center center no-repeat #535353;
  cursor: row-resize;
}
.splitter-horizontal-2 {
  flex: 0 0 auto;
  height: 18px;
  background: url(https://williamcunningham.me/codebox/hsizegrip.png) center center no-repeat #535353;
  cursor: row-resize;
}
.splitter-horizontal-3 {
  flex: 0 0 auto;
  height: 18px;
  background: url(https://williamcunningham.me/codebox/hsizegrip.png) center center no-repeat #535353;
  cursor: row-resize;
}

/*RIGHT COLUMN*/
#right {
  flex: 1 1 auto;
  height: calc(100vh - 82.88px);
}

/*the dragger between left column and right column*/
.splitter {
  flex: 0 0 auto;
  width: 18px;  
  background: url(https://williamcunningham.me/codebox/vsizegrip.png) center center no-repeat #535353;
  min-height: 200px;
  cursor: col-resize;  
}

  iframe {
    width: 99%;
    /*height: 100%;*/ 
    background-color: #fff;
  }
    <h1 class="title">Code Editor</h1>
    <div id="main">
      
      <div id="left" class="left-column">
        <div class="code-container stretch">
          <textarea id="html" placeholder="HTML" class="dragger scroll emmet-syntax-html"></textarea>
        </div>
        <div class="splitter-horizontal">
            </div>
        <div class="code-container-2 stretch">
          <textarea id="css" placeholder="CSS" class="dragger scroll emmet-syntax-css"></textarea>
        </div>
        <div class="splitter-horizontal-2">
            </div>
        <div class="code-container-3 stretch">
          <textarea id="js" placeholder="JavaScript" class="scroll"></textarea>
        </div>
                <div class="splitter-horizontal-3">
            </div>
      </div><!-- end left -->
      <div class="splitter">
      </div>
      <div id="right">
        <!-- where the final code is inserted -->
        
          <iframe id="code"></iframe>
          <footer>
            <button id="save">Save</button>
            <button id="clear">Clear</button>
          </footer>
        
      </div><!-- end right -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://williamcunningham.me/codebox/jquery-resizable.js"></script>

最佳答案

我能够弄清楚如何解决这个问题。调整大小时,如果鼠标移到 iframe 上,则会停止调整大小事件。为了克服这个问题,我在调整大小时在 iframe 上添加了一个绝对定位的元素。

关于jquery - 向 iframe 添加高度会使调整大小变得不稳定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48828872/

相关文章:

javascript - JQGrid getGridParam 数据返回空数组

jquery - 滚动顶部仅适用于 Firefox

php - 隐藏根类别并将子类别显示为菜单

jquery - 当固定 div 的底部触及此 div 的顶部时,使用 jquery 将类添加到特定的 div

javascript - 如何通过 jQuery roundSlider 插件显示项目数据?

c# - 在mvc中使用ajax发送文件和文本参数

javascript - 删除 <span> 后的文本并追加其他文本

css - 是否可以确定哪个div首先出现在移动版本上?

drupal - 应用 "text-decoration: none"时链接文本仍然带有下划线

css - 我的 CSS 侧边栏不工作,高度问题