2017-06-15 39 views
1

我已经创建与代码bootply更好地解释这个问题上:奇保证金跨屏幕变成引导面板

https://www.bootply.com/TvGcNno4qx

如果您添加注释给它一个标题和内容,然后单击添加,然后检查你会看到带有类的div,注释面板dragme和其他的1有一个保证金,充满整个屏幕。我似乎无法摆脱它。下面是一些我已经试过代码:

.note-panel{ 
     width: 300px; 
     margin-bottom: 0px; 
     margin-top: 0px; 
     margin-left:0px; 
     margin-right: 0px; 
    } 
    .panel{ 
     margin-bottom: 0px; 
     margin-top: 0px; 
     margin-left:0px; 
     margin-right: 0px; 
    } 
    .ui-draggable{ 
     margin-bottom: 0px; 
     margin-top: 0px; 
     margin-left:0px; 
     margin-right: 0px; 
    } 

这是发生在div:

<div class='note-panel dragme' id='"+noteno+"'> 
    <div class='panel panel-primary'> 
     <div class='panel-heading'> 
      <h3 class='panel-title'>"+title+"</h3> 
     </div> 
     <div class='panel-body'>"+content+"</div> 
    </div> 
</div> 

页面加载时,我经常并排2音符的一面,但由于他们在彼此之下而不是并排地加载的保证金问题。

任何帮助非常感谢!

+0

看着在控制台的计算值,我不能看到一个临界值。检查'note-panel dragme'周围和内部的所有元素都没有应用边距。有些人有'左'值和'边框'和'填充',但没有一个'保证金' – Nope

+0

我知道,这就是问题,如果你检查在铬上的笔记,你可以看到它穿过屏幕, t并排加载2个笔记... –

+0

哦,..你没有提到你想要的笔记是并排:) – Nope

回答

0

我试图在这里重新创建功能。拖动似乎工作正常,面板彼此相邻。

#noteBoardInt, 
 
header.first-row { 
 
    display: flex; 
 
    justify-content: flex-start; 
 
    align-items: center; 
 
} 
 

 
.first-row .h1 { 
 
    margin: 0; 
 
    margin-right: 2em; 
 
    padding: 0; 
 
} 
 

 
#addNewNote { 
 
    display: none; 
 
} 
 

 
.note-panel { 
 
    min-width: 300px; 
 
    max-width: 300px; 
 
} 
 

 
.note-panel:not(:first-child) { 
 
    margin-left: 1em; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> 
 
<header class="first-row"> 
 
    <h1 class="h1">Your Notes</h1> 
 
    <a class="btn btn-primary" id="addNote">Add A Note</a> 
 
</header> 
 
<div id="noteBoard"> 
 
    <div id="noteBoardInt"> 
 
    </div> 
 
</div> 
 

 
<!-- Modal --> 
 
<div id="addNewNote" class="modal fade" role="dialog"> 
 
    <div class="modal-dialog"> 
 
    <!-- Modal content--> 
 
    <div class="modal-content"> 
 
     <div class="modal-header"> 
 
     <button type="button" class="close" data-dismiss="modal">×</button> 
 
     <h4 class="modal-title">Add A new note</h4> 
 
     </div> 
 
     <div class="modal-body"> 
 
     <div class="row" style="margin-bottom: 15px;"> 
 
      <div class="col-md-4"> 
 
      <p>Title:</p> 
 
      </div> 
 
      <div class="col-md-8"> 
 
      <input id="title" class="form-control"> 
 
      </div> 
 
     </div> 
 
     <div class="row" style="margin-bottom: 15px;"> 
 
      <div class="col-md-4"> 
 
      <p>Content:</p> 
 
      </div> 
 
      <div class="col-md-8"> 
 
      <textarea id="noteContent" class="form-control"></textarea> 
 
      </div> 
 
     </div> 
 
     <div class="row" style="margin-bottom: 15px;"> 
 
      <div class="col-md-12"> 
 
      <div class="panel panel-primary"> 
 
       <div class="panel-heading"> 
 
       <h3 class="panel-title" id="panel-title"></h3> 
 
       </div> 
 
       <div class="panel-body" id="panel-body"> 
 
       </div> 
 
      </div> 
 
      </div> 
 
     </div> 
 
     <div class="row"> 
 
      <div class="col-md-2 col-md-offset-10"> 
 
      <button class="form-control btn btn-success" id="addPanel">Add</button> 
 
      </div> 
 
     </div> 
 
     </div> 
 
     <div class="modal-footer"> 
 
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div> 
 

 
<script type="text/javascript" src="//code.jquery.com/ui/1.10.1/jquery-ui.js"></script> 
 
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 

 

 

 

 

 

 
<!-- JavaScript jQuery code from Bootply.com editor --> 
 

 
<script type="text/javascript"> 
 
    var userNoteNo = 0; 
 
    var userName = "lsmith"; 
 

 

 
    $(document).ready(function() { 
 
    var response = ""; 
 
    //Put the notes on the page 
 
    $.ajax({ 
 
     url: "/myaccount/sw/note-ajax.php?command=load&username=" + userName, 
 
     type: "GET", 
 
     async: false, 
 
     success: function(data) { 
 
     var response = JSON.parse(data); 
 
     console.log(response); 
 

 
     for (var i in response) { 
 
      returnCardLoad(response[i].title, response[i].content, response[i].x, response[i].y, response[i].noteno); 
 

 
      userNoteNo++; 
 
     } 
 
     } 
 
    }); 
 
    }); 
 

 
    $("#addNote").on("click", function() { 
 
    $("#addNewNote").modal("show"); 
 
    }); 
 

 
    $("#title").on("blur", function() { 
 
    $("#panel-title").html($("#title").val()); 
 
    }); 
 

 
    $("#noteContent").on("blur", function() { 
 
    $("#panel-body").html($("#noteContent").val()); 
 
    }); 
 

 
    $("#addPanel").on("click", function() { 
 
    var html = ""; 
 
    var title = $("#title").val(); 
 
    var content = $("#noteContent").val(); 
 
    html = "<div class='note-panel dragme' id='" + userNoteNo + "'><div class='panel panel-primary'><div class='panel-heading'><h3 class='panel-title'>" + title + "</h3></div><div class='panel-body'>" + content + "</div></div></div>"; 
 
    $("#noteBoardInt").append(html); 
 

 
    //empty the inputs 
 
    $("#title").val(''); 
 
    $("#noteContent").val(''); 
 
    $("#panel-title").html(''); 
 
    $("#panel-body").html(''); 
 

 
    $("#addNewNote").modal("hide"); 
 
    addDrag(); 
 
    addToDatabase(userName, title, content, userNoteNo); 
 

 
    //LAST THING 
 
    userNoteNo++; 
 
    html = ""; 
 
    }); 
 

 
    function returnCardLoad(title, content, x, y, noteno) { 
 
    var html1 = ""; 
 
    html1 = "<div class='note-panel dragme' id='" + noteno + "'><div class='panel panel-primary'><div class='panel-heading'><h3 class='panel-title'>" + title + "</h3></div><div class='panel-body'>" + content + "</div></div></div>"; 
 
    $("#noteBoardInt").append(html1); 
 

 
    $("#" + noteno).css("top", y + "px").css("left", x + "px"); 
 
    addDrag(); 
 
    } 
 

 
    function addDrag() { 
 
    $(".dragme").draggable({ 
 
     scroll: false, 
 
     containment: "#noteBoardInt", 
 
     handle: ".panel-heading", 
 
     stop: function(event, ui) { 
 
     var noteBox = $(this) 
 
     var position = noteBox.position(); 
 
     var leftPos = position.left; 
 
     var topPos = position.top; 
 

 
     var noteNo = noteBox.attr("id"); 
 
     updateDatabase(leftPos, topPos, userName, noteNo); 
 
     } 
 
    }); 
 
    } 
 

 
    function addToDatabase(userName, title, content, noteNo) { 
 
    //Do the ajax to add record of the item to the database 
 
    var x = 0; 
 
    var y = 0; 
 

 
    $.ajax({ 
 
     url: "/myaccount/sw/note-ajax.php?command=add&username=" + userName + "&title=" + title + "&content=" + content + "&x=" + x + "&y=" + y + "&usernoteno=" + noteNo + "", 
 
     success: function() {} 
 
    }); 
 

 
    } 
 

 
    function updateDatabase(x, y, username, noteno) { 
 
    $.ajax({ 
 
     url: "/myaccount/sw/note-ajax.php?command=edit&username=" + userName + "&x=" + x + "&y=" + y + "&usernoteno=" + noteno + "", 
 
     success: function() {} 
 
    }); 
 
    } 
 
</script>

+0

这似乎导致它们捕捉到屏幕的顶部,并且不能正确地拖动... –

+0

有这么多元素定位绝对没有帮助,任何特定的原因呢?你应该尽可能地避免它。它扰乱了自然的文档流。 – Gerard

+0

那么它的页面设置为一个内部工具,而不是公共使用的大小。我使用绝对div来覆盖现有背景,然后使用包含音符的div的相对值。对我来说,有道理 –