BOT user session is getting overlapped in web channel - html

BOT user session is getting overlapped in web channel. we are using https://cdn.botframework.com/botframework-webchat/latest/webchat-es5.js
Issue: we are passing country, user unique id and email address from UI to BOT via webchat channel. user are seeing other user's data when they query for their detail i.e. my details. Is this due to using cdn reference? what could be the reason, how to resolve this?
below is the webchat code-
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous" />
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script src="https://askadamwebappdev.azurewebsites.net/AskAdam/babelpolyfill7.4.4.js"></script>
<style>
.chat-box {
background-color: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(10px);
border-radius: 4px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
border: 4px solid #12abdb;
margin: 0px;
display: none;
flex-direction: column;
box-sizing: border-box;
min-width: 320px;
min-height: 300px;
position: absolute;
height: 65%;
width: 400px;
bottom: 5px;
left: 5px;
z-index: 99999999;
}
#media only screen and (max-width: 700px) {
.chat-box {
width: 100%;
height: 100%;
transform: none;
margin: 0px;
}
.chat-box header .bot-name {
margin-left: 53px !important;
}
.chat-box header .logo {
margin-top: -4px !important;
width: 60px !important;
height: 60px !important;
}
}
button.chat-box-maximize {
background-color: #E7E7E7;
border-radius: 50%;
border: 2px solid #12abdb;
bottom: 20px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
color: White;
font-size: 30px;
height: 96px;
outline: 0;
padding: 0px;
position: fixed;
left: 20px;
width: 96px;
}
button.chat-box-maximize:focus:not(:active),
button.chat-box-maximize:focus:not(:active) {
background-color: #2a6fa8;
border-color: #2a6fa8;
}
button.chat-box-maximize:active {
background-color: White;
color: #39c;
}
button.chat-box-maximize img {
border-radius: 50%;
margin-top: 5px;
}
.chat-box header {
background-color: #12abdb;
flex-shrink: 0;
display: flex;
cursor: move;
flex-basis: 53px;
}
.chat-box header button {
width: 40px;
height: 40px;
background-color: Transparent;
border: 0;
color: White;
outline: 0;
margin-top: 9px;
cursor: default;
}
.chat-box header button.minimize {
margin-top: 3px;
}
.chat-box header button:focus:not(:active),
.chat-box header button:hover:not(:active) {
color: rgba(255, 255, 255, 0.6);
}
.chat-box header button:focus:active {
color: rgba(255, 255, 255, 0.4);
}
.chat-box header .bot-name {
font-size: 21px;
margin-left: 107px;
font-weight: bold;
color: white;
width: 142px;
}
.chat-box header .bot-title {
font-size: 15px;
margin-left: -121px;
margin-top: 27px;
color: white;
word-break: keep-all;
white-space: nowrap;
}
.chat-box header .logo {
z-index: 1;
width: 120px;
height: 120px;
position: absolute;
margin-top: -61px;
margin-left: -2px;
background-size: contain;
background-repeat: no-repeat;
background-image: url(/image/responsive/ask-adam-virtual-agent-avatar.png);
}
.chat-box header .filler {
flex: 0 10000 100%;
}
.css-1dgbgmu>.image {
background-image: url(/image/responsive/ask-adam-virtual-agent-avatar.png);
background-size: contain;
}
.css-1m1alj7 {
background-color: #12abdb !important;
}
.css-1dgbgmu {
background-color: white !important;
}
.css-1vieo9r .ac-pushButton {
color: #12abdb !important;
}
.css-1vieo9r .ac-pushButton:active {
border-color: #12abdb !important;
}
.css-1vieo9r .ac-pushButton:focus {
outline: 0;
}
.css-14x775w {
display: none;
}
.chat-box ::-moz-selection {
background: #12abdb;
}
.chat-box ::selection {
background: #12abdb;
}
.web-chat {
overflow: hidden;
width: 100%;
height: 100%;
}
.connect-spinner {
display: flex;
margin: auto;
text-align: center;
}
.connect-spinner .content {
margin: auto;
}
.connect-spinner .content .icon {
font-size: 64px;
}
.chat-box-header img {
width: 100%;
}
.chat-box {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.chat-box code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
}
.resizable .resizers {
width: 100%;
height: 100%;
box-sizing: border-box;
position: absolute;
}
.resizable .resizer {
width: 10px;
height: 10px;
position: absolute;
z-index: 999999;
}
.resizable .resizer.top-left {
position: absolute;
left: -5px;
top: -5px;
cursor: nwse-resize;
}
.resizable .resizer.top-right {
position: absolute;
right: -5px;
top: -5px;
cursor: nesw-resize;
}
.resizable .resizer.bottom-left {
position: absolute;
left: -5px;
bottom: -5px;
cursor: nesw-resize;
}
.resizable .resizer.bottom-right {
position: absolute;
right: -5px;
bottom: -5px;
cursor: nwse-resize;
}
</style>
<div id="chat-box-container" class="chat-box resizable">
<div class="resizer top-left"></div>
<div class="resizer top-right"></div>
<div class="resizer bottom-left"></div>
<div class="resizer bottom-right"></div>
<header id="chat-box-header" class="chat-header">
<div class="logo"></div>
<div class="bot-name">Ask Adam</div>
<div class="bot-title">Virtual Assistant</div>
<div class="filler"></div>
<button onclick="minimizeConversation()" class="minimize">
<i class="far fa-window-minimize fa-lg"></i>
</button>
<button onclick="restartConversation()" class="restart-conversation">
<i class="fas fa-times fa-lg"></i>
</button>
</header>
<div class="web-chat" id="webchat" role="main"></div>
</div>
<button onclick="minimizeConversation()" class="chat-box-maximize">
<!--i class="far fa-comment-alt"></i-->
<img src="/image/responsive/ask-adam-virtual-agent-avatar.png" />
</button>
<script type="text/javascript">
"use strict";
function makeResizableDiv(div) {
const element = document.querySelector(div);
const resizers = document.querySelectorAll(div + " .resizer");
const minimum_size = 320;
let original_width = 0;
let original_height = 0;
let original_x = 0;
let original_y = 0;
let original_mouse_x = 0;
let original_mouse_y = 0;
for (let i = 0; i < resizers.length; i++) {
const currentResizer = resizers[i];
currentResizer.addEventListener("mousedown", function(e) {
e.preventDefault();
original_width = parseFloat(
getComputedStyle(element, null)
.getPropertyValue("width")
.replace("px", "")
);
original_height = parseFloat(
getComputedStyle(element, null)
.getPropertyValue("height")
.replace("px", "")
);
original_x = element.getBoundingClientRect().left;
original_y = element.getBoundingClientRect().top;
original_mouse_x = e.pageX;
original_mouse_y = e.pageY;
window.addEventListener("mousemove", resize);
window.addEventListener("mouseup", stopResize);
});
function resize(e) {
if (currentResizer.classList.contains("bottom-right")) {
const width = original_width + (e.pageX - original_mouse_x);
const height = original_height + (e.pageY - original_mouse_y);
if (width > minimum_size) {
element.style.width = width + "px";
}
if (height > minimum_size) {
element.style.height = height + "px";
}
} else if (currentResizer.classList.contains("bottom-left")) {
const height = original_height + (e.pageY - original_mouse_y);
const width = original_width - (e.pageX - original_mouse_x);
if (height > minimum_size) {
element.style.height = height + "px";
}
if (width > minimum_size) {
const left = original_x + (e.pageX - original_mouse_x);
element.style.width = width + "px";
element.style.left =
original_x + (e.pageX - original_mouse_x) + "px";
}
} else if (currentResizer.classList.contains("top-right")) {
const width = original_width + (e.pageX - original_mouse_x);
const height = original_height - (e.pageY - original_mouse_y);
if (width > minimum_size) {
element.style.width = width + "px";
}
if (height > minimum_size) {
element.style.height = height + "px";
const top = original_y + (e.pageY - original_mouse_y);
element.style.top = top + "px";
}
} else {
const width = original_width - (e.pageX - original_mouse_x);
const height = original_height - (e.pageY - original_mouse_y);
if (width > minimum_size) {
element.style.width = width + "px";
element.style.left =
original_x + (e.pageX - original_mouse_x) + "px";
}
if (height > minimum_size) {
element.style.height = height + "px";
const top = original_y + (e.pageY - original_mouse_y);
element.style.top = top + "px";
}
}
}
function stopResize() {
window.removeEventListener("mousemove", resize);
}
}
}
makeResizableDiv(".resizable");
(function() {
dragElement(document.getElementById("chat-box-container"));
function dragElement(elmnt) {
var pos1 = 0,
pos2 = 0,
pos3 = 0,
pos4 = 0;
if (document.getElementById("chat-box-header")) {
document.getElementById(
"chat-box-header"
).onmousedown = dragMouseDown;
} else {
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
elmnt.style.top = elmnt.offsetTop - pos2 + "px";
elmnt.style.left = elmnt.offsetLeft - pos1 + "px";
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
})();
var minimized = true;
var store;
var directLine;
var token = "this_is_bot_secret";
(function() {
botInit();
})();
var usr_country = "india";
var usr_mail = "this_is_username#accenture.com";
var usr_login_id = "this_is_userloginId_unique_Across_org";
function botInit() {
var styleOptions = {
botAvatarImage: "/image/responsive/ask-adam-virtual-agent-avatar.png"
};
store = window.WebChat.createStore({}, function(_ref) {
var dispatch = _ref.dispatch;
return function(next) {
return function(action) {
if (action.type === "DIRECT_LINE/CONNECT_FULFILLED") {
dispatch({
type: "WEB_CHAT/SEND_EVENT",
payload: {
name: "USER",
value: {
"COUNTRY": usr_country,
"ID": usr_login_id,
"MAIL": usr_mail,
"Service_Now": "true"
}
}
});
} else if (action.type === "DIRECT_LINE/DISCONNECT_FULFILLED") {
return;
}
return next(action);
};
};
});
directLine = window.WebChat.createDirectLine({
token: token
});
window.WebChat.renderWebChat({
directLine: directLine,
store: store,
styleOptions: styleOptions
},
document.getElementById("webchat")
);
document.querySelector("#webchat > *").focus();
}
function minimizeConversation() {
var maximizeButton = document.getElementsByClassName(
"chat-box-maximize"
)[0];
var chatBox = document.getElementsByClassName("chat-box")[0];
if (minimized) {
maximizeButton.style.display = "none";
chatBox.style.display = "flex";
minimized = false;
} else {
maximizeButton.style.display = "inline";
chatBox.style.display = "none";
minimized = true;
}
}
function restartConversation() {
minimizeConversation();
const element = document.getElementById("chat-box-container");
element.removeAttribute("style")
var messages = document.getElementsByClassName("css-1qyo5rb");
while (messages.length > 0)
messages[0].parentNode.removeChild(messages[0]);
botInit();
}
</script>

It doesn't look like you're specifying a user ID in the props or the token. Have a look at this documentation.
Specify a userID. There are two ways to specify the userID: in props, or in the token when generating the token call (createDirectLine()). If both methods are used to specify the userID, the token userID property will be used, and a console.warn will appear during runtime. If the userID is provided via props but is prefixed with 'dl', e.g. 'dl_1234', the value will be thrown and a new ID generated. If userID is not specified, it will default to a random user ID. Multiple users sharing the same user ID is not recommended; their user state will be shared, which creates a security risk when authenticating.

Related

Html Car Game with speed

Statement
Increase the speed of the player by 1 after every 5 seconds, starting speed should always be 5.
Increment the score only when the rear end of my Car (yellow) has passed the rear end of an enemy Car(green). The score should be incremented by 10 at each passing. Score shouldn’t increment in any other case.
Prerequisites
Starting speed is not 5 after restarting the game.
Speed goes from 5 to 6 in less than 5 seconds after restarting the game.
Speed is incrementing very fast after restarting the game 3-4 times.
Score is incremented when the enemy car passes the end of screen instead of my Car.
Sometimes, the score is not incremented during the passing, when my Car is also moving upwards at the time of passing.
Score is still continuously incrementing like before.
const score = document.querySelector('.score');
const startScreen = document.querySelector('.startScreen');
const gameArea = document.querySelector('.gameArea');
startScreen.addEventListener('click', initializeGame);
let player = {
speed: 5,
score: 0
};
let keys = {
ArrowUp: false,
ArrowDown: false,
ArrowLeft: false,
ArrowRight: false
}
document.addEventListener('keydown', keyDown);
document.addEventListener('keyup', keyUp);
function keyDown(e) {
e.preventDefault();
keys[e.key] = true;
}
function keyUp(e) {
e.preventDefault();
keys[e.key] = false;
}
function isCollide(a, b) {
aRectangle = a.getBoundingClientRect();
bRectangle = b.getBoundingClientRect();
return !((aRectangle.bottom < bRectangle.top) ||
(aRectangle.top > bRectangle.bottom) ||
(aRectangle.right < bRectangle.left) ||
(aRectangle.left > bRectangle.right))
}
function moveLines() {
let lines = document.querySelectorAll('.lines');
lines.forEach(function(item) {
if (item.y >= 700) {
item.y -= 750;
}
item.y += player.speed;
item.style.top = item.y + "px";
})
}
function endGame() {
player.start = false;
startScreen.classList.remove('hide');
startScreen.innerHTML = "Game over Your final score is " + player.score +
" press here to restart the game.";
}
function moveEnemy(myCar) {
let enemyCarList = document.querySelectorAll('.enemyCar');
enemyCarList.forEach(function(enemyCar) {
if (isCollide(myCar, enemyCar)) {
endGame();
}
if (enemyCar.y >= 750) {
enemyCar.y = -300;
enemyCar.style.left = Math.floor(Math.random() * 350) + "px";
}
enemyCar.y += player.speed;
enemyCar.style.top = enemyCar.y + "px";
})
}
function runGame() {
let car = document.querySelector('.myCar');
let road = gameArea.getBoundingClientRect();
if (player.start) {
moveLines();
moveEnemy(car);
if (keys.ArrowUp && player.y > (road.top + 150)) {
player.y -= player.speed
}
if (keys.ArrowDown && player.y < (road.bottom - 85)) {
player.y += player.speed
}
if (keys.ArrowLeft && player.x > 0) {
player.x -= player.speed
}
if (keys.ArrowRight && player.x < (road.width - 50)) {
player.x += player.speed
}
car.style.top = player.y + "px";
car.style.left = player.x + "px";
player.score++;
score.innerText = "Score: " + player.score + "\n Speed: " + player.speed;
}
}
function initializeGame() {
startScreen.classList.add('hide');
gameArea.innerHTML = "";
player.start = true;
player.score = 0;
window.requestAnimationFrame(runGame);
for (x = 0; x < 5; x++) {
let roadLine = document.createElement('div');
roadLine.setAttribute('class', 'lines');
roadLine.y = (x * 150)
roadLine.style.top = roadLine.y + "px";
gameArea.appendChild(roadLine);
}
let car = document.createElement('div');
car.setAttribute('class', 'myCar');
gameArea.appendChild(car);
player.x = car.offsetLeft;
player.y = car.offsetTop;
for (x = 0; x < 3; x++) {
let enemyCar = document.createElement('div');
enemyCar.setAttribute('class', 'enemyCar');
enemyCar.y = ((x + 1) * 350) * -1;
enemyCar.style.top = enemyCar.y + "px";
enemyCar.style.left = Math.floor(Math.random() * 350) + "px";
gameArea.appendChild(enemyCar);
}
}
* {
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
}
.hide {
display: none;
}
.car Game {
width: 100%;
height: 100vh;
background-image: ;
background-repeat: no-repeat;
background-size: 100% 100%;
}
.my Car {
width: 50px;
height: 90px;
/* background: red; */
position: absolute;
bottom: 120px;
background-image: u r l('');
background-repeat: no-repeat;
background-size: 100% 100%;
}
.enemy Car {
width: 30px;
height: 60px;
/* background: red; */
position: absolute;
bottom: 120px;
background-image: ('');
/* border-radius: 15px; */
background-repeat: no-repeat;
background-size: 100% 100%;
}
.lines {
width: 10px;
height: 100px;
background: white;
position: absolute;
margin-left: 195px;
}
.game Area {
width: 400px;
height: 100vh;
background: #2d3436;
margin: auto;
position: relative;
overflow: hidden;
border-right: 7px dashed #c8d6e5;
border-left: 7px dashed #c8d6e5;
}
.score {
position: absolute;
top: 15px;
left: 40px;
background: #10ac84;
width: 300px;
line-height: 70px;
text-align: center;
color: white;
font-size: 1.5rem;
font-family: Arial, Helvetica, sans-serif;
box-shadow: 0 5px 5px #777;
}
.start Screen {
position: absolute;
background-color: #ee5253;
left: 24%;
top: 40%;
transform: translate(-50% -50%);
color: white;
z-index: 1;
text-align: center;
border: 1px solid #ff6b6b;
padding: 15px;
margin: auto;
width: 50%;
cursor: pointer;
letter-spacing: 5;
font-size: 20px;
word-spacing: 3;
line-height: 30px;
text-transform: uppercase;
box-shadow: 0 5px 5px #777;
}
<div class="carGame">
<div class="score"></div>
<div class="startScreen">
<p>
press here to start Arrow key to move if you hit another car you will lose.
</p>
</div>
<div class="gameArea"> </div>
</div>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
*{margin: 0; padding: 0; font-family: Arial, Helvetica, sans-
serif;}
.hide{ display: none; }
.carGame{
width: 100%;
height: 100vh;
background-image: url('bg.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}
.myCar{
width: 50px;
height: 90px;
/* background: red; */
position: absolute;
bottom: 120px;
background-image: url('car2.png');
background-repeat: no-repeat;
background-size: 100% 100%;
}
.enemyCar{
width: 30px;
height: 60px;
/* background: red; */
position: absolute;
bottom: 120px;
background-image: url('car4.png');
/* border-radius: 15px; */
background-repeat: no-repeat;
background-size: 100% 100%;
}
.lines{
width: 10px;
height: 100px;
background: white;
position: absolute;
margin-left: 195px;
}
.gameArea{
width: 400px;
height: 100vh;
background: #2d3436;
margin: auto;
position: relative;
overflow: hidden;
border-right: 7px dashed #c8d6e5;
border-left: 7px dashed #c8d6e5;
}
.score{
position: absolute;
top: 15px;
left: 40px;
background: #10ac84;
width: 300px;
line-height: 70px;
text-align: center;
color: white;
font-size: 1.5rem;
font-family: Arial, Helvetica, sans-serif;
box-shadow: 0 5px 5px #777;
}
.startScreen{
position: absolute;
background-color: #ee5253;
left: 24%;
top: 40%;
transform: translate(-50% -50%);
color: white;
z-index: 1;
text-align: center;
border: 1px solid #ff6b6b;
padding: 15px;
margin: auto;
width: 50%;
cursor: pointer;
letter-spacing: 5;
font-size: 20px;
word-spacing: 3;
line-height: 30px;
text-transform: uppercase;
box-shadow: 0 5px 5px #777;
}
</style>
</head>
<body>
<div class="carGame">
<div class="score"></div>
<div class="startScreen">
<p>
press here to start <br>
Arrow key to move <br>
if you hit another car you will lose.
</p>
</div>
<div class="gameArea "> </div>
</div>
<script>
const score = document.querySelector('.score');
const startScreen = document.querySelector('.startScreen');
const gameArea = document.querySelector('.gameArea');
startScreen.addEventListener('click', initializeGame);
let player = { speed:5, score:0 };
let keys = {ArrowUp:false, ArrowDown:false, ArrowLeft:false, ArrowRight:false}
document.addEventListener('keydown', keyDown);
document.addEventListener('keyup', keyUp);
function keyDown(e){
e.preventDefault();
keys[e.key] = true;
}
function keyUp(e){
e.preventDefault();
keys[e.key] = false;
}
function isCollide(a,b){
aRect = a.getBoundingClientRect();
bRect = b.getBoundingClientRect();
return !((aRect.bottom < bRect.top) ||
(aRect.top > bRect.bottom) ||
(aRect.right < bRect.left) ||
(aRect.left > bRect.right))
}
function moveLines() {
let lines = document.querySelectorAll('.lines');
lines.forEach(function(item) {
if(item.y >= 700){
item.y -= 750;
}
item.y += player.speed;
item.style.top = item.y + "px";
})
}
function endGame(){
player.start = false;
startScreen.classList.remove('hide');
startScreen.innerHTML = "Game over <br> Your final socre is " + player.score
+ " <br> press here to restart the game.";
}
function moveEnemy(myCar) {
let enemyCarList = document.querySelectorAll('.enemyCar');
enemyCarList.forEach(function(enemyCar) {
if(isCollide(myCar, enemyCar)){
endGame();
}
if(enemyCar.y >= 750){
enemyCar.y = -300;
enemyCar.style.left = Math.floor(Math.random() * 350) + "px";
}
enemyCar.y += player.speed;
enemyCar.style.top = enemyCar.y + "px";
})
}
function runGame(){
let car = document.querySelector('.myCar');
let road = gameArea.getBoundingClientRect();
if(player.start){
moveLines();
moveEnemy(car);
if(keys.ArrowUp && player.y > (road.top + 150)) {player.y -= player.speed}
if(keys.ArrowDown && player.y < (road.bottom-85)) {player.y += player.speed}
if(keys.ArrowLeft && player.x>0) {player.x -= player.speed}
if(keys.ArrowRight && player.x < (road.width - 50)) {player.x += player.speed}
car.style.top = player.y + "px";
car.style.left = player.x + "px";
window.requestAnimationFrame(runGame);
player.score++;
score.innerText = "Score: " + player.score + "\nSpeed: " + player.speed;
}
}
function initializeGame() {
startScreen.classList.add('hide');
gameArea.innerHTML = "";
player.start = true;
player.score = 0;
window.requestAnimationFrame(runGame);
for(x=0; x<5; x++)
{
let roadLine = document.createElement('div');
roadLine.setAttribute('class', 'lines');
roadLine.y = (x*150)
roadLine.style.top = roadLine.y + "px";
gameArea.appendChild(roadLine);
}
let car = document.createElement('div');
car.setAttribute('class', 'myCar');
gameArea.appendChild(car);
player.x = car.offsetLeft;
player.y = car.offsetTop;
for(x=0; x<3; x++)
{
let enemyCar = document.createElement('div');
enemyCar.setAttribute('class', 'enemyCar');
enemyCar.y = ((x+1) * 350) * -1;
enemyCar.style.top = enemyCar.y + "px";
enemyCar.style.left = Math.floor(Math.random() * 350) + "px";
gameArea.appendChild(enemyCar);
}
}
</script>
</body>
</html>

How to arrange text into single line and center (align) it horizontally?

Could somebody give advice, how to arrange text into single line and center (align) it horizontally?
var words = document.getElementsByClassName('word');
var wordArray = [];
var currentWord = 0;
words[currentWord].style.opacity = 1;
for (var i = 0; i < words.length; i++) {
splitLetters(words[i]);
}
function changeWord() {
var cw = wordArray[currentWord];
var nw = currentWord == words.length-1 ? wordArray[0] : wordArray[currentWord+1];
for (var i = 0; i < cw.length; i++) {
animateLetterOut(cw, i);
}
for (var i = 0; i < nw.length; i++) {
nw[i].className = 'letter behind';
nw[0].parentElement.style.opacity = 1;
animateLetterIn(nw, i);
}
currentWord = (currentWord == wordArray.length-1) ? 0 : currentWord+1;
}
function animateLetterOut(cw, i) {
setTimeout(function() {
cw[i].className = 'letter out';
}, i*80);
}
function animateLetterIn(nw, i) {
setTimeout(function() {
nw[i].className = 'letter in';
}, 340+(i*80));
}
function splitLetters(word) {
var content = word.innerHTML;
word.innerHTML = '';
var letters = [];
for (var i = 0; i < content.length; i++) {
var letter = document.createElement('span');
letter.className = 'letter';
letter.innerHTML = content.charAt(i);
word.appendChild(letter);
letters.push(letter);
}
wordArray.push(letters);
}
changeWord();
setInterval(changeWord, 6000);
.text2 {
font-family: Quicksand-Medium;
font-weight: 600;
position: absolute;
width: 200px;
height: 40px;
top: 30%;
margin-top: -20px;
margin-bottom: 50px;
}
p2 {
display: inline-block;
vertical-align: top;
margin: 0;
}
.word {
font-family: Quicksand-Medium;
font-weight: 600;
position: absolute;
width: 600px;
opacity: 0;
white-space: pre;
}
.letter {
display: inline-block;
position: relative;
float: left;
transform: translateZ(25px);
transform-origin: 50% 50% 25px;
}
.letter.out {
transform: rotateX(90deg);
transition: transform 0.32s cubic-bezier(0.55, 0.055, 0.675, 0.19);
}
.letter.behind {
transform: rotateX(-90deg);
}
.letter.in {
transform: rotateX(0deg);
transition: transform 0.38s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.wisteria {
color: #8e44ad;
}
.belize {
color: #2980b9;
}
.pomegranate {
color: #c0392b;
}
.green {
color: #16a085;
}
.midnight {
color: #2c3e50;
}
<div class="text2" style="z-index:100; padding-top: 50px; padding-bottom: 50px; font-size: 25px" ><center>
<p2>Mes siūlome
<span class="word wisteria">pastovų darbą.</span>
<span class="word belize">laiku mokamą atlyginimą.</span>
<span class="word pomegranate">socialines garantijas.</span>
<span class="word green">galimybes tobulėti.</span>
<span class="word midnight">nuolaidas tinklo parduotuvėse.</span>
</p2>
</center></div>
Adding width: 100% on .text2 should get the whole block in center somewhat.
Also use <p> instead of <p2> and set its width to max character count for your text. eg: 40ch. And remove width: 600px; from .word
Hope it helps.

Div underlapps its siblings

I'm struggling with a div that underlapps its siblings what breaks the usability.
I'd like to achieve that the content of #container starts directly under header and that the content gets scrollable immediately when hitting footer instead of underlapping footer. (To reproduce just add some tasks)
For the header, I tried to apply some padding to #container and it kinda works, but breaks when window gets rezized. For the bottom at footer, neither margin or padding worked.
What am I doing wrong?
document.addEventListener('DOMContentLoaded', function() {
window.input = document.getElementById('input');
window.container = document.getElementById('container');
window.input.addEventListener('keypress', function(event) {
if (event.keyCode == '13' && window.input.value != '') {
addTask();
}
});
/**for (let i = 0; i < localStorage.length; i++) {
addTask(i, 'auto');
}*/
});
const checkButton = () => {
if (window.input.value != '') {
addTask();
}
};
const addTask = (index, type) => {
let task = document.createElement('div');
if (!type) {
task.textContent = window.input.value;
//localStorage.setItem(window.input.value, window.input.value);
} else {
//task.textContent = localStorage.getItem(localStorage.key(index));
}
task.classList.add('task');
let closeButton = document.createElement('div');
closeButton.textContent = 'X';
closeButton.classList.add('close');
closeButton.setAttribute('onclick', 'removeTask(this)');
task.appendChild(closeButton);
window.container.appendChild(task);
window.input.value = '';
};
const removeTask = (task) => {
window.container.removeChild(task.parentNode);
//localStorage.removeItem(task.parentNode.textContent.substring(0, task.parentNode.textContent.length - 1));
};
#input {
width: 80%;
color: #E6E6FA;
}
body {
background-color: #E9FEF2;
}
#container {
padding-top: 6%; /** My try with the padding */
width: 100%;
}
h5 {
margin: 1% 1%;
}
header {
position: fixed;
top: 0;
width: 100%;
background-color: #333;
color: #E6E6FA;
}
footer {
overflow: hidden;
background-color: #333;
position: fixed;
bottom: 0;
width: 100%;
padding: 10px;
text-align: center;
}
.task {
text-align: left;
padding: 1% 1% 1% 1%;
background-color: #acaaaa;
width: 100%;
}
.task:nth-child(odd) {
background-color: #ccc7c7;
}
.close {
text-align: center;
width: 2%;
color: #FF0000;
float: right;
margin-right: 1%;
}
.close:hover {
background-color: #FF0000;
color: #FFFFFF;
cursor: pointer;
}
<!doctype html>
<html>
<head>
<title>What's up?</title>
<meta charset="utf-8">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
</head>
<body>
<header>
<h5>Your tasks:</h5>
</header>
<div id="container"></div>
<footer>
<input type="text" placeholder="Enter task here..." id="input" autofocus>
<a class="waves waves-light btn" onclick="checkButton()">Add</a>
</footer>
</body>
</html>
I also have a codepen to play around with.
The issue
The problem is that you are using position: fixed; on the header and footer but don't know how much height they will take up, this means you can't use margin or padding to reliably "reserve" the space.
The solution
If header and footer have a fixed height you could add top and bottom padding to #container to "clear" them.
If header and footer don't have a set height one way to ensure that they stay at the top and bottom while the container takes up the remaining space is to use flexbox instead.
document.addEventListener('DOMContentLoaded', function() {
window.input = document.getElementById('input');
window.container = document.getElementById('container');
window.input.addEventListener('keypress', function(event) {
if (event.keyCode == '13' && window.input.value != '') {
addTask();
}
});
/**for (let i = 0; i < localStorage.length; i++) {
addTask(i, 'auto');
}*/
});
const checkButton = () => {
if (window.input.value != '') {
addTask();
}
};
const addTask = (index, type) => {
let task = document.createElement('div');
if (!type) {
task.textContent = window.input.value;
//localStorage.setItem(window.input.value, window.input.value);
} else {
//task.textContent = localStorage.getItem(localStorage.key(index));
}
task.classList.add('task');
let closeButton = document.createElement('div');
closeButton.textContent = 'X';
closeButton.classList.add('close');
closeButton.setAttribute('onclick', 'removeTask(this)');
task.appendChild(closeButton);
window.container.appendChild(task);
window.input.value = '';
};
const removeTask = (task) => {
window.container.removeChild(task.parentNode);
//localStorage.removeItem(task.parentNode.textContent.substring(0, task.parentNode.textContent.length - 1));
};
#input {
width: 80%;
color: #E6E6FA;
}
body {
background-color: #E9FEF2;
display: flex;
flex-direction: column;
overflow: hidden;
height: 100vh;
}
#container {
/*padding-top: 6%;*/ /** My try with the padding */
width: 100%;
flex: 1 1 auto;
overflow-y: auto;
}
h5 {
margin: 1% 1%;
}
header {
/*position: fixed;
top: 0;*/
width: 100%;
background-color: #333;
color: #E6E6FA;
}
footer {
overflow: hidden;
background-color: #333;
/*position: fixed;
bottom: 0;*/
width: 100%;
padding: 10px;
text-align: center;
}
.task {
text-align: left;
padding: 1% 1% 1% 1%;
background-color: #acaaaa;
width: 100%;
}
.task:nth-child(odd) {
background-color: #ccc7c7;
}
.close {
text-align: center;
width: 2%;
color: #FF0000;
float: right;
margin-right: 1%;
}
.close:hover {
background-color: #FF0000;
color: #FFFFFF;
cursor: pointer;
}
<!doctype html>
<html>
<head>
<title>What's up?</title>
<meta charset="utf-8">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
</head>
<body>
<header>
<h5>Your tasks:</h5>
</header>
<div id="container"></div>
<footer>
<input type="text" placeholder="Enter task here..." id="input" autofocus>
<a class="waves waves-light btn" onclick="checkButton()">Add</a>
</footer>
</body>
</html>
One way to solve this is you need to get the height of both <header> and <footer> during runtime (because the heights are dynamic), this is also needed if you want to be as responsive as possible.
Then after getting the heights, add padding-top: height of header and padding-bottom:height of footer to the body. Oh, and also remove the padding-top in the #container
I used JQuery for this, you can convert it to JavaScript if you want.
It still looks like it is still overlapping, but you can immediately scroll after reaching the footer
/*
You can convert this to javascript if you want
*/
$(function() {
var headerHeight = $('header').outerHeight();
var footerHeight = $('footer').outerHeight();
$('body').css('padding-top', headerHeight);
$('body').css('padding-bottom', footerHeight);
});
document.addEventListener('DOMContentLoaded', function() {
window.input = document.getElementById('input');
window.container = document.getElementById('container');
window.input.addEventListener('keypress', function(event) {
if (event.keyCode == '13' && window.input.value != '') {
addTask();
}
});
/**for (let i = 0; i < localStorage.length; i++) {
addTask(i, 'auto');
}*/
});
const checkButton = () => {
if (window.input.value != '') {
addTask();
}
};
const addTask = (index, type) => {
let task = document.createElement('div');
if (!type) {
task.textContent = window.input.value;
//localStorage.setItem(window.input.value, window.input.value);
} else {
//task.textContent = localStorage.getItem(localStorage.key(index));
}
task.classList.add('task');
let closeButton = document.createElement('div');
closeButton.textContent = 'X';
closeButton.classList.add('close');
closeButton.setAttribute('onclick', 'removeTask(this)');
task.appendChild(closeButton);
window.container.appendChild(task);
window.input.value = '';
};
const removeTask = (task) => {
window.container.removeChild(task.parentNode);
//localStorage.removeItem(task.parentNode.textContent.substring(0, task.parentNode.textContent.length - 1));
};
#input {
width: 80%;
color: #E6E6FA;
}
body {
background-color: #E9FEF2;
}
#container {
width: 100%;
}
h5 {
margin: 1% 1%;
}
header {
position: fixed;
top: 0;
width: 100%;
background-color: #333;
color: #E6E6FA;
}
footer {
overflow: hidden;
background-color: #333;
position: fixed;
bottom: 0;
width: 100%;
padding: 10px;
text-align: center;
}
.task {
text-align: left;
padding: 1% 1% 1% 1%;
background-color: #acaaaa;
width: 100%;
}
.task:nth-child(odd) {
background-color: #ccc7c7;
}
.close {
text-align: center;
width: 2%;
color: #FF0000;
float: right;
margin-right: 1%;
}
.close:hover {
background-color: #FF0000;
color: #FFFFFF;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
<body>
<header>
<h5>Your tasks:</h5>
</header>
<div id="container"></div>
<footer>
<input type="text" placeholder="Enter task here..." id="input" autofocus>
<a class="waves waves-light btn" onclick="checkButton()">Add</a>
</footer>
</body>
This will work for you:
I have just added Fixed px padding to top and bottom considering your header and footer.
document.addEventListener('DOMContentLoaded', function() {
window.input = document.getElementById('input');
window.container = document.getElementById('container');
window.input.addEventListener('keypress', function(event) {
if (event.keyCode == '13' && window.input.value != '') {
addTask();
}
});
/**for (let i = 0; i < localStorage.length; i++) {
addTask(i, 'auto');
}*/
});
const checkButton = () => {
if (window.input.value != '') {
addTask();
}
};
const addTask = (index, type) => {
let task = document.createElement('div');
if (!type) {
task.textContent = window.input.value;
//localStorage.setItem(window.input.value, window.input.value);
} else {
//task.textContent = localStorage.getItem(localStorage.key(index));
}
task.classList.add('task');
let closeButton = document.createElement('div');
closeButton.textContent = 'X';
closeButton.classList.add('close');
closeButton.setAttribute('onclick', 'removeTask(this)');
task.appendChild(closeButton);
window.container.appendChild(task);
window.input.value = '';
};
const removeTask = (task) => {
window.container.removeChild(task.parentNode);
//localStorage.removeItem(task.parentNode.textContent.substring(0, task.parentNode.textContent.length - 1));
};
#input {
width: 80%;
color: #E6E6FA;
}
body {
background-color: #E9FEF2;
}
#container {
padding: 49px 0 71px;
/** My try with the padding */
width: 100%;
}
h5 {
margin: 1% 1%;
}
header {
position: fixed;
top: 0;
width: 100%;
background-color: #333;
color: #E6E6FA;
}
footer {
overflow: hidden;
background-color: #333;
position: fixed;
bottom: 0;
width: 100%;
padding: 10px;
text-align: center;
}
.task {
text-align: left;
padding: 1% 1% 1% 1%;
background-color: #acaaaa;
width: 100%;
}
.task:nth-child(odd) {
background-color: #ccc7c7;
}
.close {
text-align: center;
width: 2%;
color: #FF0000;
float: right;
margin-right: 1%;
}
.close:hover {
background-color: #FF0000;
color: #FFFFFF;
cursor: pointer;
}
<!doctype html>
<html>
<head>
<title>What's up?</title>
<meta charset="utf-8">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
</head>
<body>
<header>
<h5>Your tasks:</h5>
</header>
<div id="container"></div>
<footer>
<input type="text" placeholder="Enter task here..." id="input" autofocus>
<a class="waves waves-light btn" onclick="checkButton()">Add</a>
</footer>
</body>
</html>
Hope this was helpfull.

How to make <label> the same height as <input type=“text”>

I like to give a label/span the same height as an input text field, which should be placed right next to it.
I tried to follow the recommendations from this question - but none of them worked.
I created this fiddle: it shows my overlay. But the numbers should be on the left side and NO gaps should be visible at all.
var overlay = document.createElement('div');
overlay.className = "overlay";
document.body.appendChild(overlay);
var list = document.createElement('div');
var toLeft = document.createElement('span');
var toRight = document.createElement('span');
toLeft.textContent = "<";
toLeft.className = "control";
toRight.textContent = ">";
toRight.className = "control";
overlay.appendChild(list);
overlay.appendChild(toLeft);
overlay.appendChild(toRight);
// build list
var selection_history = [1, 2, 3, 4];
for (var i in selection_history) {
var label = document.createElement('label');
label.textContent = parseInt(i) + ".";
label.className = "list";
var input = document.createElement('input');
input.className = "comment";
var br = document.createElement('br');
list.appendChild(label);
list.appendChild(input);
list.appendChild(br);
}
.overlay {
position: fixed;
border: 1px solid black;
right: 0px;
}
.list {
display: block;
width: 24px;
}
.comment {
display: block;
float: left;
height: 20px;
}
.control {
width: 50%;
}
.list, .control {
display: inline-block;
height: 25px;
background-color: black;
color: white;
font-family: Arial;
font-weight: bold;
text-align: center;
cursor: pointer;
}
.list:hover, .control:hover {
background-color: white;
color: black;
}
Any ideas?
try to set a left float for the list , then you can see the numbers on left side
.list {
display: block;
width: 24px;
float:left;
}

How can i make such percentage curves using css3

How can i make such percentage curves using css3
See this link
HTML
<div class="container">
<div id="percent"></div>
<svg id="svg"></svg>
<p><label for="perc-input">Percent:</label><input maxlength="2" type="text" id="input" value="65"/></p>
<a class="btn" id="run">Run</a>
</div>
CSS
#import url(http://fonts.googleapis.com/css?family=Share+Tech);
body {
background: #efefef;
}
.container {
width: 400px;
height: 200px;
position: relative;
margin: auto;
font-family: 'Share Tech', sans-serif;
color: #444;
}
#percent, #svg {
width: 200px;
height: 200px;
position: absolute;
top: 0;
left: 0;
}
#percent {
line-height: 20px;
height: 20px;
width 100%;
top: 90px;
font-size: 43px;
text-align: center;
color: #3da08d;
opacity: 0.8
}
p, .btn {
position: relative;
left: 220px;
width: 200px;
display: block;
text-transform: uppercase;
font-size: 24px;
top: 30px;
}
.btn {
text-align: center;
background: #5fc2af;
color: #fff;
width: 120px;
height: 37px;
line-height: 37px;
cursor: pointer;
}
input {
border: 0;
outline: 0;
border-bottom: 1px solid #eee;
width: 30px;
font-family: helvetica;
font-size: 24px;
text-transform: capitalise;
font-family: 'Share Tech', sans-serif;
background: transparent;
}
JS
var canvasSize = 200,
centre = canvasSize/2,
radius = canvasSize*0.8/2,
s = Snap('#svg'),
path = "",
arc = s.path(path),
startY = centre-radius,
runBtn = document.getElementById('run'),
percDiv = document.getElementById('percent'),
input = document.getElementById('input');
input.onkeyup = function(evt) {
if(isNaN(input.value)) {
input.value = '';
}
};
runBtn.onclick = function() {
run(input.value/100);
};
function run(percent) {
var endpoint = percent*360;
Snap.animate(0, endpoint, function (val) {
arc.remove();
var d = val,
dr = d-90;
radians = Math.PI*(dr)/180,
endx = centre + radius*Math.cos(radians),
endy = centre + radius * Math.sin(radians),
largeArc = d>180 ? 1 : 0;
path = "M"+centre+","+startY+" A"+radius+","+radius+" 0 "+largeArc+",1 "+endx+","+endy;
arc = s.path(path);
arc.attr({
stroke: '#3da08d',
fill: 'none',
strokeWidth: 12
});
percDiv.innerHTML = Math.round(val/360*100) +'%';
}, 2000, mina.easeinout);
}
run(input.value/100);
By rachstock