2014-09-04 36 views
1

我正在做一個聊天腳本,以儘量減少特定的聊天,我似乎無法弄清楚如何使div的頭壓下!有沒有辦法做到這一點??我研究了這一點,但無法找到獲得我想要的結果的方法。如何使我的HTML DIVS按下,而不是向上

我的HTML代碼如下

<?php 

$usrid = "Joel"; 

?><!DOCTYPE html> 
<HTML> 
<HEAD> 
    <LINK REL="stylesheet" HREF="css/style.css"> 
    <SCRIPT SRC="js/jquery-2.1.1.min.js"></SCRIPT> 
    <SCRIPT> 
function onTestChange() { 
    var key = window.event.keyCode; 

    // If the user has pressed enter 
    if (key == 13) { 
     event.preventDefault(); 
     post(); 
    } 
    else { 
     return true; 
    } 
} 

function post() 
{ 
    document.getElementById('txtArea').value = ""; 
} 
    </SCRIPT> 
    </HEAD> 
    <BODY><?php 

$file = simplexml_load_file("xml/joel.xml"); 

echo" 
    <DIV CLASS=\"chatbox\"> 
    <DIV CLASS=\"title\"> 
    <SPAN CLASS=\"name\"> 
    $file->subject 
    </SPAN> 
    <SPAN CLASS=\"buttons\"> 
     <BUTTON ONCLICK=\"minimize()\" NAME=\"Minimize\" ID=\"min\">-</BUTTON><BUTTON  ONCLICK=\"close()\" NAME=\"Close\">x</BUTTON> 
    </SPAN> 
    </DIV> 
    <DIV ID=\"body\" CLASS=\"hidden\"> 
    <DIV CLASS=\"history\">"; 

foreach($file->post as $post) 
{ 
if($post->auth == $usrid) 
{ 
    echo" 
    <DIV CLASS=\"self\"> 
    <DIV CLASS=\"self_left\"> 
     $post->content 
    </DIV> 
    <DIV CLASS=\"self_right\"> 
     $post->auth 
    </DIV> 
    </DIV>  
    "; 
    } 
else 
{ 
    echo" 
    <DIV CLASS=\"other\"> 
    <DIV CLASS=\"other_left\"> 
     $post->auth 
    </DIV> 
    <DIV CLASS=\"other_right\"> 
     $post->content 
    </DIV> 
    </DIV>  
    "; 
} 
} 

echo" </DIV> 
    <DIV CLASS=\"input\"> 
    <DIV ID=\"input\"> 
    <DIV CLASS=\"text\"> 
     <TEXTAREA NAME=\"input\" ONKEYPRESS=\"onTestChange()\" ID=\"txtArea\"></TEXTAREA> 
    </DIV> 
    <DIV CLASS=\"submit\"> 
     <BUTTON SRC=\"images/button1.png\" ONCLICK=\"post()\">Send</BUTTON> 
    </DIV> 
    </DIV> 
    </DIV> 
    </DIV> 
    </DIV> 
</BODY> 
</HTML>"; 

?> 

和我的CSS是 :: - WebKit的滾動條 { 寬度:8像素; height:8px; }

::-webkit-scrollbar-track 
{ 
background: url(../images/bg.png); 
} 

::-webkit-scrollbar-thumb 
{ 
background: rgba(0,0,0,0.5); 
border-radius: 25px; 
} 

.chatbox 
{ 
width: 250px; 
margin: 0 auto; 
border: 1px solid black; 
border-top-left-radius: 25px; 
border-top-right-radius: 25px; 
overflow: hidden; 
flex-direction: column; 
} 

.title 
{ 
width: 100%; 
border-bottom: 1px solid black; 
display: inline-block; 
background: #436ED2; 
flex-direction: column; 
} 

.name 
{ 
width: calc(50% - 10px); 
float: left; 
text-align: left; 
margin-top: 3px; 
padding-left: 10px; 
} 

.buttons 
{ 
width: 50%; 
float: right; 
text-align: right; 
} 

.buttons button 
{ 
width: 24px; 
height: 24px; 
border: none; 
background: none; 
outline: none; 
} 

.history 
{ 
width: 90%; 
margin: 0 auto; 
height: 300px; 
border: 1px solid black; 
margin-top: 5px; 
overflow: auto; 
overflow-x: hidden; 
} 

.self 
{ 
width: 100%; 
background: #c6d3f1; 
display: inline-block; 
margin-top: -4px; 
padding-bottom: 5px; 
padding-top: 5px; 
} 

.self_left 
{ 
width: calc(80% - 6px); 
float: left; 
text-align: right; 
padding-right: 5px; 
border-right: 1px solid black; 
} 

.self_right 
{ 
width: calc(20% - 6px); 
float: right; 
text-align: left; 
padding-left: 5px; 
border-left: 1px solid black; 
} 


.other 
{ 
width: 100%; 
background: #f1d3c6; 
display: inline-block; 
margin-top: -4px; 
padding-bottom: 5px; 
padding-top: 5px; 
} 

.other_left 
{ 
width: calc(20% - 6px); 
float: left; 
text-align: right; 
padding-right: 5px; 
border-right: 1px solid black; 
} 

.other_right 
{ 
width: calc(80% - 6px); 
float: right; 
text-align: left; 
padding-left: 5px; 
border-left: 1px solid black; 
} 

.input 
{ 
width: 90%; 
margin: 0 auto; 
height: 90%; 
margin-top: 5px; 
} 

#input 
{ 
width: 100%; 
display: inline-block; 
} 

textarea 
{ 
resize: none; 
width: 75%; 
height: 40px; 
float: left; 
} 

.input button 
{ 
float: right; 
width: 20%; 
height: 46px; 
top: 10px; 
} 

.hidden 
{ 
display: none; 
flex-direction: column; 
} 

我希望我的DIV稱爲標題時,我調用腳本最小化(),我還沒有添加下移。

+0

請告訴我們你有什麼到目前爲止 – Devin 2014-09-04 19:15:05

+0

請張貼代碼或網站。 – Brian 2014-09-04 19:15:09

回答

5

您可以使用柔性盒來實現這個

看看這篇文章:http://css-tricks.com/snippets/css/a-guide-to-flexbox/

這將使div的,而不是往下走的了:

.container { 
    flex-direction: column-reverse; 
} 
+0

這是一個偉大的現代化解決方案,如果瀏覽器的兼容性問題值得關注,這並不值得提問者解決。 – 2014-09-08 19:03:02

+0

哈哈@MikeLegacy最初的問題是「如何讓我的HTML DIVS下推而不是上漲」。然後他更新了這個問題,並提出了一個不同的事情haha – 2014-09-08 19:20:53

0

最簡單的方法是我在改變問題後發現,我問的是得到正確的結果,非常簡單

.chatbox 
{ 
position: fixed; 
bottom: 0px; 
} 

就是這樣

+0

哈哈我在更新之前給出了我的答案。隨着更新更清楚你想達到什麼,沒有更新,我認爲你想改變你的元素的堆棧順序:P – 2014-09-04 21:46:00

+0

這是一個有用的想法,只是在這種情況下,雖然我很驚訝我的答案是如此簡單 – Jdoonan 2014-09-05 19:12:59

+0

是的,我誤解了你的問題。我以爲你想改變DIVS堆疊在一起的方向。如果你對答案更清楚,我會說'position:fixed;'真的很快哈哈 – 2014-09-05 19:42:07

0

您可以使用jQuery的.animate()方法將每個聊天div縮放到「最小化」/「最大化」狀態。

下面是一個不完善的例子,我只是散列一起作爲起點:

jsFiddle Demo

HTML:

<div class="chatBox" id="chat-17"> 
    <div class="chatTitle"> 
     <div class="titleText">This is chat title</div> 
     <div class="titleMin"> v</div> 
    </div> 
    <div class="chatBody"> 
     Chat message goes here 
    </div> 
</div> 

的jQuery:

$('.titleText').click(function(){ 
    if ($(this).hasClass('minTitle')){ 
     $(this).removeClass('minTitle'); 
     $(this).parent().parent().removeClass('minimized'); 
    }else{ 
     $(this).addClass('minTitle'); 
     var cb = $(this).parent().parent(); 
     cb.addClass('minimized'); 
     //cb.animate(function(){top: '150',left: '10'},500); 
    } 
}); 

CSS:添加

.chatBox{width:100%;border:1px solid blue;overflow:hidden;} 
.chatTitle{width:100%;height:20px;} 
.titleText{width:95%;height:100%;color:white;font-weight:bold;float:left;background:black;} 
.titleMin{width:4.5%;height:100%;color:red;font-weight:bold;float:left;text-align:center;background:black;} 
.titleMin:hover{cursor:pointer;cursor:hand;} 
.chatBody{width:100%;height:150px;padding:10px;background:wheat;} 

額外的CSS,因爲例如不工作:

.titleText:hover{cursor:pointer;cursor:hand;} 
.minimized{height:5px;width:5px;position:absolute;top:150px;} 
span{font-weight:bold;color:red;} 

資源:

http://viralpatel.net/blogs/understanding-jquery-animate-function/

http://www.tutorialscollection.com/jquery-animate-how-to-animate-in-jquery-using-animate-method/

http://www.1stwebdesigner.com/tutorials/jquery-animation-tutorial/

相關問題