Html Car Game with speed - html

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>

Related

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.

BOT user session is getting overlapped in web channel

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.

Stop left margin pushing element off page

This is my code:
https://jsfiddle.net/rzcos32n/
I have this code:
function isItANumber(el) {
var element1 = document.getElementById("circle").innerHTML;
var percent = parseFloat(element1)*100;
percent+='%';
var increased = parseInt(el.innerText);
var element = document.getElementById("Value");
if (isNaN(increased) || element1 >= 0) {
document.getElementById("Result").innerHTML = "KanBan";
document.getElementById("circle").style.marginLeft = percent;
};
if (isNaN(increased) || element1 >= 0.33) {
document.getElementById("Result").innerHTML = "ScrumBan";
document.getElementById("circle").style.marginLeft = percent;
};
if (isNaN(increased) || element1 >= 0.66) {
document.getElementById("Result").innerHTML = "Scrum";
document.getElementById("circle").style.marginLeft = percent;
}
if (isNaN(increased) || element1 > 0.9) {
document.getElementById("Result").innerHTML = "Scrum";
document.getElementById("circle").style.marginRight = '0%';
}
}
var element = document.getElementById("circle");
isItANumber(element);
#line {
width: 100%;
/* 2 */
height: 5px;
background: gray;
position:relative;
margin-top: 30px;
}
#circle {
height: 50px;
width: 50px;
border-radius: 50%;
background: blue;
text-align: center;
color: white;
font-weight: 700;
line-height: 50px;
font-size: 14px;
position:absolute;
margin-top:-22.5px;
}
<div id="Result"></div>
<div id="line">
<div id="circle">
1.0
</div>
</div>
I set the position of the circle on the line horizontally depending on the percentage value in the circle. So if it's '1' that means 100%.
I do this by assigning a margin-left to it, and it works perfectly for most values, except when its a high value like 1 it pushes the circle completely off the page.
Is there a way to have it so the circle always stays on the page, even when it's margin-left is either 0% or 100%?
I added var percent = "calc("+parseFloat(element1)*100+"% - 50px)"; in that way you got 100% but we have to subtract circle width (50px)
function isItANumber(el) {
var element1 = document.getElementById("circle").innerHTML;
var percent = "calc("+parseFloat(element1)*100+"% - 50px)";
var increased = parseInt(el.innerText);
var element = document.getElementById("Value");
if (isNaN(increased) || element1 >= 0) {
document.getElementById("Result").innerHTML = "KanBan";
document.getElementById("circle").style.marginLeft = percent;
};
if (isNaN(increased) || element1 >= 0.33) {
document.getElementById("Result").innerHTML = "ScrumBan";
document.getElementById("circle").style.marginLeft = percent;
};
if (isNaN(increased) || element1 >= 0.66) {
document.getElementById("Result").innerHTML = "Scrum";
document.getElementById("circle").style.marginLeft = percent;
}
if (isNaN(increased) || element1 > 0.9) {
document.getElementById("Result").innerHTML = "Scrum";
document.getElementById("circle").style.marginRight = '0%';
}
}
var element = document.getElementById("circle");
isItANumber(element);
#line {
width: 100%;
/* 2 */
height: 5px;
background: gray;
position:relative;
margin-top: 30px;
}
#circle {
height: 50px;
width: 50px;
border-radius: 50%;
background: blue;
text-align: center;
color: white;
font-weight: 700;
line-height: 50px;
font-size: 14px;
position:absolute;
margin-top:-22.5px;
}
<div id="Result"></div>
<div id="line">
<div id="circle">
1.0
</div>
</div>
You have not needed marginLeft property you can use left property because it's a positioned element. here your accepted output or maybe it helps you.
function isItANumber(el) {
var element1 = document.getElementById("circle").innerHTML;
var percent = parseFloat(element1)*100;
percent+='%';
var increased = parseInt(el.innerText);
var element = document.getElementById("Value");
if (isNaN(increased) || element1 >= 0 && element1 < 0.33 ) {
document.getElementById("Result").innerHTML = "KanBan";
document.getElementById("circle").style.left = percent;
};
if (isNaN(increased) || element1 >= 0.33 && element1 < 0.66) {
document.getElementById("Result").innerHTML = "ScrumBan";
document.getElementById("circle").style.left = percent;
};
if (isNaN(increased) || element1 >= 0.66 && element1 < 0.9) {
document.getElementById("Result").innerHTML = "Scrum";
document.getElementById("circle").style.left = percent;
}
if (isNaN(increased) || element1 > 0.9) {
document.getElementById("Result").innerHTML = "Scrum";
document.getElementById("circle").style.left = 'auto';
document.getElementById("circle").style.right = '0';
}
}
var element = document.getElementById("circle");
isItANumber(element);
#line {
box-sizing: border-box;
/* 2 */
height: 5px;
background: gray;
position:relative;
margin: 30px auto 0 auto;
}
#circle {
height: 50px;
width: 50px;
border-radius: 50%;
background: blue;
text-align: center;
color: white;
font-weight: 700;
line-height: 50px;
font-size: 14px;
position:absolute;
margin-top:-22.5px;
transition: 0.3s;
left: 0;
}
<div id="Result"></div>
<div id="line">
<div id="circle">
1.0
</div>
</div>
=== Thank you ===
removed javascript that is adding 100% margin-left and replaced with margin-left:auto this will place the circle at the right side and used margin-top: -22.5px to place it on top of the line. thanks
function isItANumber(el) {
var element1 = document.getElementById("circle").innerHTML;
var percent = parseFloat(element1) * 100;
percent += '%';
var increased = parseInt(el.innerText);
var element = document.getElementById("Value");
if (isNaN(increased) || element1 >= 0) {
document.getElementById("Result").innerHTML = "KanBan";
document.getElementById("circle").style.marginLeft = percent;
};
if (isNaN(increased) || element1 >= 0.33) {
document.getElementById("Result").innerHTML = "ScrumBan";
};
if (isNaN(increased) || element1 >= 0.66) {
document.getElementById("Result").innerHTML = "Scrum";
document.getElementById("circle").style.marginLeft = percent;
}
if (isNaN(increased) || element1 > 0.9) {
document.getElementById("Result").innerHTML = "Scrum";
document.getElementById("circle").style.marginRight = '0%';
}
}
var element = document.getElementById("circle");
isItANumber(element);
#line {
width: 100%;
/* 2 */
height: 5px;
background: gray;
position: relative;
margin-top: 30px;
padding-top: 1px;
}
#circle {
height: 50px;
width: 50px;
border-radius: 50%;
background: blue;
text-align: center;
color: white;
font-weight: 700;
line-height: 50px;
font-size: 14px;
/* position: absolute; */
margin-top: -22.5px;
/* margin: auto; */
/* margin-top: 100px; */
margin-left: auto !important;
}
<div id="Result"></div>
<div id="line">
<div id="circle">
1.0
</div>
</div>

Scroll relative to device size

I am making a site where you can click on a button and it will scroll you down to the information below. My issue is that the size of the opening screen is relative to the device screen. That means that a fixed scroll can be too far or not far enough on different devices. In summary my question is: how do i jump the exact device sreen height?
Here is my code:`
<div id='textPage1'>
<div id='leesMeer'>
<a href="#page2" class='leesMeer'type="button" value='Lees Meer'>LEES MEER</a>
</div>
</div>
<div id='page2'>
<div id='textPage2'>
<p>hi</p>
</div>
</div>
And my css:
#textPage1 {
float: right;
margin-right: 100px;
z-index: -1;
}
#beschrijving {
font-family: agency;
font-size: 20px;
color: #f2f2f2;
letter-spacing: 2px;
transform: scale(1, 1.1);
line-height: 30px;
z-index: 1;
margin-left: 50px;
}
.leesMeer {
font-family: agency;
font-size: 30px;
color: #f2f2f2;
border: 5px solid #f2f2f2;
border-radius: 15px;
padding: 12px 40px 12px 40px;
text-decoration: none;
-webkit-transition-duration: 0.5s;
position: absolute;
}
You can use Javascript to specify the scroll down like this example:
HTML:
<div class="first"><button type="button" onclick="smoothScroll(document.getElementById('second'))">Click Me!</button></div>
<div class="second" id="second">Hi</div>
CSS:
.first {
width: 100%;
height: 1000px;
background: #ccc;
}
.second {
width: 100%;
height: 1000px;
background: #999;
}
Javascript:
window.smoothScroll = function(target) {
var scrollContainer = target;
do { //find scroll container
scrollContainer = scrollContainer.parentNode;
if (!scrollContainer) return;
scrollContainer.scrollTop += 1;
} while (scrollContainer.scrollTop == 0);
var targetY = 0;
do { //find the top of target relatively to the container
if (target == scrollContainer) break;
targetY += target.offsetTop;
} while (target = target.offsetParent);
scroll = function(c, a, b, i) {
i++; if (i > 30) return;
c.scrollTop = a + (b - a) / 30 * i;
setTimeout(function(){ scroll(c, a, b, i); }, 20);
}
// start scrolling
scroll(scrollContainer, scrollContainer.scrollTop, targetY, 0);
}
here is the code in jsfiddle http://jsfiddle.net/rjSfP/

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