2017-06-16 58 views
0

提交後消息頁面重新加載與滾動的消息框內容。我想滾動下來,像facebook messenger這樣的圖像中顯示。我嘗試了很多方法,但沒有得到正確的輸出結果。提交消息頁面後重新加載消息框內容滾動up.i想滾動下來

enter image description here 聊天形式

<?php foreach ($b_to_c as $row) { ?> 

    <?php 
    if ($row->From == 'customer') { 
     ?> 
     <div class="left"> 
      <div class="row"> 
       <div class="col-md-1"> 


        <?php if (empty($roww->customer_image[0]) || empty($roww->supplier_image)) { ?> 
         <img src="<?php echo base_url(); ?>images/default.jpg" class="img-circle" width="30px" height="30px"/> 

        <?php } else { ?> 
         <img src="<?php echo 'data:image;base64,' . $roww->supplier_image; ?>" class="img-circle" width="30px" height="30px"/> 

        <?php } ?> 

                           <!--<img src="<?php // echo 'data:image;base64,' .$roww->supplier_image;     ?>" class="img-circle" width="30px" height="30px"/>--> 
       </div> 
       <div class="col-md-11"> 

        <div class="left_msg_block"> 

         <?php $timestamp1 = strtotime($row->msg_sent_time); ?> 
         <?php $mesgtimming = date(' D-h:i A', $timestamp1); ?> 
         <div class="left_messagetext"><a href="#" data-toggle="tooltip" title="<?php echo $mesgtimming; ?>"><?php echo $row->message; ?></a></div> 

        </div> 
       </div> 
      </div> 
     </div> 
    <?php } else { ?>     
     <div class="right"> 
      <div class="row"> 
       <div class="col-md-12"> 
        <div class="right_msg_block"> 
         <?php $timestamp1 = strtotime($row->msg_sent_time); ?> 
         <?php $mesgtimming = date(' D-h:i A', $timestamp1); ?> 
         <div class="right_messagetext"><a href="#" data-toggle="tooltip" title="<?php echo $mesgtimming; ?>"><?php echo $row->message; ?></a></div> 

        </div> 
       </div>          
      </div> 
     </div> 
     <?php 
    } 
} 
?> 

CSS代碼

.left_messagetext a{ 
     color: rgba(0, 0, 0, 1); 
    } 
    .right_messagetext{ 
     background-color: #0084ff; 
     margin: 1px 0; 
     padding: 6px 12px; 
     word-wrap: break-word; 
     clear: right; 
     float: right; 
     border-bottom-left-radius: 1.3em; 
     border-top-left-radius: 1.3em; 
     max-width: 60%; 
    } 
    .right_messagetext a{ 
     color:#fff; 
    } 
    .scrollstarts{ 
     overflow-y:scroll; 
     max-height: 500px; 
     overflow-x:hidden; 
     padding:3%; 
    } 
.left_messagetext{ 
    background-color: #d0cbcb; 
    margin: 1px 0; 
    padding: 6px 12px; 
    border-bottom-right-radius: 1.3em; 
    border-top-right-radius: 1.3em; 
    clear: left; 
    float: left; 
    word-wrap: break-word; 
    max-width: 60%; 
} 

控制器代碼

$data['b_to_c'] = $this->Profile_model->Buyer_s($pid); 
     $this->load->view('buyermessageview', $data) 

型號代碼

public function Buyer_s($pid) { 

     $this->db->select('*'); 
     $this->db->from('communication'); 
     $this->db->join('supplier_otherdetails', 'supplier_otherdetails.supplierid_fk = communication.supplier_id'); 
     $this->db->join('customer_registration', 'communication.Customer_id=customer_registration.id'); 
     $array = array('communication.product_id' => $pid, 'communication.Customer_id' => $this->session->id); 
//  $where = "communication.From='customer' and 'communication.Customer_id',$this->session->id"; 
     $this->db->where($array); 
     $this->db->order_by("msg_sent_time", "asc"); 
     $query = $this->db->get(); 
     $results = []; 
     if ($query->num_rows() > 0) { 

      $results = $query->result(); 
     } 
     return $results; 
    } 

回答

0

也許你可以使用JavaScript滾動到頁面底部?

例子:

<script> 
    // scroll to the bottom of the page 
    window.scrollTo(0,document.body.scrollHeight); 
</script> 

或者,如果它只是在你要往下走的消息框,你可以使用:

<script> 
    // scroll to the bottom of messagediv 
    var messageDiv = document.getElementById("your_div"); 
    messageDiv.scrollTop = messageDiv.scrollHeight; 
</script> 

你當然可以包裹腳本函數並隨時調用它,在setTimeout()的定時基礎上或在頁面加載等...