- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在底部的每个网页中显示实时聊天框。我做到了,但校准工作不正常。我想让它类似于这个实时聊天框示例:( https://www.tawk.to/testimonials/ )。请帮助我如何做到这一点。
我的代码是:https://jsfiddle.net/fn77d0de/2/
// JavaScript Document
var username = "";
function send_message(bot_response) {
var prevState = $("#container").html();
console.log(prevState.length);
if (prevState.length > 8) {
prevState = prevState + "<br>";
}
$("#container").html(prevState + "<span class='current_message'>" + "<span class='chatBot'>Chatbot: </span>" + bot_response + "</span>");
$("#container").scrollTop($("#container").prop("scrollHeight"));
$(".current_message").hide();
$(".current_message").delay(500).fadeIn();
$(".current_message").removeClass("current_message");
//$("#container").html("<span class='chatBot'>Chatbot: </span>" + message );
}
function get_userName() {
//send_message("Hello, what is your name?");
username = "${outParams.userName}";
send_message("Nice to meet you " + username + ", how may can may I help you.");
}
function ai(newMessage) {
var id = "1";
var path = "http://localhost:8080/vfim/chatService.do";
if (username.length < 1) {
username = newMessage;
send_message("Nice to meet you " + username + ", how are you doing?");
} else if (newMessage.indexOf("how are you") >= 0) {
send_message("Thanks, I am good!");
} else if (newMessage.indexOf("time") >= 0) {
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
send_message("Current time is: " + h + ":" + m);
} else {
$.post(path,
{
userMessage: newMessage
},
function(data) {
//alert("inside ajax"+data);
send_message(data);
});
/* $.get(path,function(data){
console.log("no match");
console.log(data);
send_message(data);
}); */
}
}
$(function() {
$.ajax({
url: "chatWindow.html",
type: 'GET',
success: function(data) {
$('body').append(data);
//$('#content').html($(data).find('#content').html());
$('head').append('<link rel="stylesheet" href="style.css" type="text/css" />');
var logged_in = false;
$(".pageTitleHeader").click(function() {
logged_in = !logged_in;
checkLogin();
});
function checkLogin() {
if (logged_in)
$(".contentBox").show();
else
$(".contentBox").hide();
}
}
});
get_userName();
$("#textarea").keypress(function(event) {
if (event.which == 13) {
if ($("#enter").prop("checked")) {
console.log("enter pressed");
$("#send").click();
event.preventDefault();
//$("#textarea").val("");
}
}
});
$("#send").click(function() {
var userName = "<span class='uname'>You: </span>";
var latestMessage = $("#textarea").val();
$("#textarea").val("");
var prevState = $("#container").html();
//console.log(prevState.length);
if (prevState.length > 1) {
prevState = prevState + "<br>";
}
$("#container").html(prevState + userName + latestMessage);
$("#container").scrollTop($("#container").prop("scrollHeight"));
ai(latestMessage);
});
});
setTimeout(function() {
$("#live-chat").css({
"display": "block"
});
}, 900); // 30 seconds in MS
// Store our panel into a variable.
var $myPanel = $("#live-chat");
// Get the height of the panel dynamically.
var $myPanelHeight = parseInt($myPanel.height());
// Immediately set the opacity to 0 - to hide it and set its bottom to minus its height.
$myPanel.css({
"opacity": 0,
"bottom": "-" + $myPanelHeight + "px"
});
// Set a timeout for the panel to slide and fade in.
setTimeout(function() {
$myPanel.animate({
// The CSS properties we want to animate (opacity and bottom position).
opacity: 1,
bottom: '0'
}, 2000, function() {
// Animation complete.
// You can put other code here to do something after it has slid-in.
});
}, 30000); // 30 seconds in MS
function getScripts(scripts, callback) {
var progress = 0;
scripts.forEach(function(script) {
$.getScript(script, function() {
if (++progress == scripts.length) callback();
});
});
}
body {
margin: 0;
background-color: #f2f2f2;
font-family: arial, sans-serif;
font-weight: bold;
}
#header {
width: 100%;
height: 60px;
background-color: #333;
box-shadow: 0px 4px 2px #333;
}
#header>h1 {
width: 1024px;
margin: 0px auto;
color: white;
}
#container {
width: 1024px;
height: 400px;
margin: 0px auto;
margin-top: 20px;
background-color: white;
border: 1px solid #333;
overFlow: scroll;
}
#controls {
width: 1024px;
margin: 0px auto;
}
#textarea {
resize: none;
width: 940px;
}
#send {
font-size: 24px;
position: absolute;
}
.uname {
color: blue;
font-weight: bold;
}
.chatBot {
color: green;
font-weight: bold;
}
#live-chat {
position: absolute;
bottom: 0px;
right: 0px;
/* width: 200px;
height: 100px;*/
z-index: 5;
background: #789;
border-radius: 5px 5px 0 0;
padding: 10px;
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<a href="page1.html">Page1</a>
<a href="page2.html">Page2</a>
<a href="page3.html">Page3</a>
<div id="live-chat">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr class="livepageTitle">
<td width="50%" class="maincurve" scope="col">
<h1 class="pageTitleHeader">Live Chat</h1>
</td>
<td width="50%" class="maincurvecls" scope="col">
<table border="0" align="right" cellpadding="0" cellspacing="0" id="tblPageContent">
<tr>
<!-- BODY STARTS -->
<td height="31" align="right" valign="middle" nowrap class="innerPageTopLeftBGWithText">
<dt:timeZone id="IST">IST</dt:timeZone>
<dt:format pattern="dd-MMM-yyyy [hh:mm a z]" timeZone="IST">
<dt:currentTime />
</dt:format>
</td>
<!-- <td width="14" height="31" align="right" valign="middle"><a href="#" title="Help" onClick="helpWindow('corporate/admin/admin_ma_accrts_add.htm')"><img src="/sbijava/images/help_icon.jpg" alt="Help" width="14" height="13" border="0" align="middle"></a></td> -->
<!-- <td width="29" height="31" align="right" valign="middle" class="helpAndPrintLinks" onClick="helpWindow('corporate/admin/admin_ma_accrts_add.htm')"><a href="#" title="Help">Help</a> </td> -->
</tr>
<!-- BODY ENDS -->
<!-- FOOTER STARTS -->
<!-- FOOTER ENDS -->
</table>
</td>
</tr>
<!-- Tab starts -->
<tr class="contentBox">
<td colspan="2" align="left" valign="top" scope="row" class="pageContentBG">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabtblbrdr">
<!-- <tr>
<td colspan="6" class="innerPageSectionHeading">Select the Date Range </td>
</tr> -->
<tr>
<td align="left" width="30%">
<!-- <div id="header">
<h1>jQuery Chatbot v. 1.0</h1>
</div> -->
<div id="container"> </div>
<div id="controls">
<textarea id="textarea" placeholder="Enter your message here..."></textarea>
<button id="send">Send</button>
<br>
<input checked type="checkbox" id="enter">
<label>Send on enter</label>
</div>
</td>
</tr>
</table>
<br>
</td>
</tr>
</table>
</div>
</body>
</html>
最佳答案
好的,让我首先告诉您为什么这不起作用。原因有很多。
导致此中断的具体样式如下。
#controls {
width: 1024px; /* This width */
margin: 0px auto;
}
#textarea {
resize: none;
width: 940px; /* This width */
}
#container {
width: 1024px; /* This width */
height: 400px;
margin: 0px auto;
margin-top: 20px;
background-color: white;
border: 1px solid #333;
overFlow: scroll;
}
您可以在这里看到,在您使用的众多类中,宽度非常大。您也使用过表格,我不太清楚为什么。不需要它们,尤其是对于您正在从事的工作。我已经把所有这些都去掉了,至于你需要什么,你可以用纯 css 来实现。
还有更多我想改变的,但这个答案是专门解决你关于对齐的问题。您可以在下面找到我的更改。如果您对我所做的有任何疑问,我很乐意解释。
#live-chat {
position: absolute;
bottom: 0px;
right: 20px;
width: 300px;
height: auto;
z-index: 5;
background: #789;
border-radius: 5px 5px 0 0;
padding: 10px;
display: block;
box-sizing: border-box;
}
#send {
font-size: 24px;
margin-top: 10px;
}
#textarea {
resize: none;
width: 100%;
}
<a href="page1.html">Page1</a>
<a href="page2.html">Page2</a>
<a href="page3.html">Page3</a>
<div id="live-chat">
<h1 class="pageTitleHeader">Live Chat</h1>
<!--
<dt:timeZone id="IST">IST</dt:timeZone>
<dt:format pattern="dd-MMM-yyyy [hh:mm a z]" timeZone="IST">
<dt:currentTime />
</dt:format> -->
<a href="#" title="Help" onClick="helpWindow('corporate/admin/admin_ma_accrts_add.htm')"><img src="/sbijava/images/help_icon.jpg" alt="Help" width="14" height="13" border="0" align="middle"></a>
<textarea id="textarea" placeholder="Enter your message here..."></textarea>
<button id="send">Send</button>
<input checked type="checkbox" id="enter">
</div>
关于jquery - 实时聊天框的 CSS 对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48456904/
我想知道 gmail 聊天如何允许用户连接到 AIM,然后像登录到 AIM 一样聊天。 做起来容易吗?怎么做到的? 有人知道任何类似的开源工具吗? 谢谢! 最佳答案 如果你在谈论编程,这里是源代码示例
大家好,我正在尝试制作一个游戏,两个主持人联系起来,他们将“掷硬币”,并确定谁先出局。我决定从基本代码开始。但是我真的没有主意。 Thread server2 = new Thread(new Ser
我已经创建了一个只有 1 个房间的聊天室、私有(private)消息、审核以及一切,现在一切都很好!当我测试聊天时,我意识到在聊天中输入的所有消息都会被保存,如果有很多人使用聊天,它很快就会占用 Fi
当用户键入内容并出现软键盘时,我必须保持聊天回收器 View 的当前项目可见。目前,它覆盖了聊天,我需要回收器 View 项目与键盘一起显示。 我在 list 中尝试了这些: -android:win
我有一个服务器客户端应用程序集。 (家庭作业) 到目前为止,我已经弄清楚如何让多个客户端连接到服务器并让服务器聚合客户端发送的消息,以及如何让服务器将客户端的消息发送回客户端并将其显示在聊天 Pane
如何从我的应用程序发送/接收 Facebook 聊天消息?它是用 .Net、C# 编写的。 最佳答案 如果你可以使用 C,你就可以使用 libpurple (GPL) 和 pidgin-faceboo
我正在使用启用的 Ajax-Wcf 服务开发 Asp.Net 聊天。这是一个非常简单的聊天引擎,其中消息对话框意味着一对一(单个用户),但是我不知道如何管理(以最佳方式)通知新消息可用性。例如,假设有
我的任务是通过服务器构建一个客户端到客户端的聊天程序。客户端 A 将向服务器发送一条消息,然后服务器将消息转发给客户端 B,反之亦然。所有这一切都将同时发生,直到其中一个将其关闭。我有以下程序。 服务
我创建了一个聊天,用户可以在其中输入文本的输入字段。当他输入文本并按下发送(或输入)时,文本位于输入字段上方。像这样: 我想要的:我希望输入字段位于页面底部。我使用 position: absolut
出于个人兴趣,我尝试定义一个模拟 AI,它基于他学到的信息和互联网搜索,以便提供比系统知道的更多的细节。 我举了一个 child 的例子,当他出生时他需要学习一切,他听到了很多然后提出了一些答案。他的
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 3年前关闭。 Improve this qu
我已经开始聊天了,但我已经将用户的 ID 硬编码到 Chat.php 中。 当他们登录站点时,我的登录名将他们的电子邮件设置为 session ( $_SESSION['email']=$email;
当用户点击像 Start a viber chat with us 这样的链接时,我试图找到一种方法来开始 viber 聊天。但到目前为止我没有找到正确的URI来做到这一点。例如,我知道我可以使用 s
我是 Javascript(纯 javascript)新手,我正在尝试创建一个执行以下操作的聊天 Controller 应用程序。 用户输入内容。 有人对我的知识库进行了后调用。 服务器响应消息。 目
已关闭。这个问题是 not about programming or software development 。目前不接受答案。 这个问题似乎不是关于 a specific programming
如果用户在 x 秒/分钟内处于非事件状态,我想结束聊天,以便我们的代理不必等待聊天自行关闭。我还想在结束聊天之前将标签附加到聊天中,以便我可以看到这是由于不活动造成的。 最佳答案 此内容归功于 j
我正在此网站中构建新网站,客户需要 24/7 实时客户支持。我想在网站上集成 Skype 聊天 聊天界面应该在客户端的网站上。 最佳答案 您可以通过在网站上放置 Skype 按钮来使用它。 http:
事实上,我只是开始积极练习 swing,以便我的理论知识能派上用场:) 我已经为聊天 GUI 实现做了很多工作,但最终遇到了一些问题。所以我决定从头开始重新设计聊天 GUI,但我需要为其选择正确的组件
已关闭。这个问题是 not about programming or software development 。目前不接受答案。 这个问题似乎不是关于 a specific programming
我正在尝试进行简单的聊天,其中连接到服务器的用户发送消息,其他用户接收消息。 这是我的 html: function setupEventSource()
我是一名优秀的程序员,十分优秀!