/* event.target.src = 'https://site.com/img/basket.svg' */
if (event.target.src == 'img/basket.svg') { // <-- вы проверяете
D.canvas.width = window.innerWidth;
D.canvas.height = window.innerHeight;
window.addEventListener('resize', function(event) {
D.Init();
}, true);
Как именно?
html{
--footer-height : 50px; /* высота футера*/
}
body{
position:relative;
padding-bottom: var( --footer-height );
}
footer{
position: absolute;
bottom: 0;
min-height: var( --footer-height );
}
Возник вопрос возможно ли избежать вложенного цикла в данной задачи и как это можно сделать?
const table = document.createElement('table'),header = ["id","name", "address"],
message = [header, // <-- первый элемент
{id:1, name:"two_1", address:"add_1"},
{id:2, name:"two_2", address:"add_2"},
{id:3, name:"two_3", address:"add_3"},
{id:4, name:"two_4", address:"add_4"},
{id:5, name:"two_5", address:"add_5"},
{id:6, name:"two_6", address:"add_6"}
];
table.innerHTML =
message.map((m, i)=>`<tr>${header.map((h,j)=>(j=i?'td':'th',l=i?m[h]:h,`<${j}>${l}</${j}>`)).join('')}</tr>`).join('');
document.querySelector('body').appendChild(table); // <-- выводим таблицу ))
Заголовки таблицы являются ключи первого элемента message[0]
Object.prototype.keys = function(){
return Object.keys(this);
}
Object.prototype.keysToString = function(){
return Object.keys(this).join(' ');
}
const obj = {
one: true,
two: true
}
console.log(obj.keys());
console.log(obj.keysToString());
for(let handler of handlers) {
console.log(handler); // <--- this
if (handler.length == 0) {
if (isYes) {
handler() }
} else {
handler(isYes);
}
}
<?php if(!isset($_REQUEST['width'])){ ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=5.0, user-scalable=yes">
</head>
<body>
<script>
location.replace(location.protocol+'//'+location.host + location.pathname +'?width=' + document.body.offsetWidth);
</script>
</body>
</html>
<?php }else{
$width = intval($_REQUEST['width']);
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $width >= 769 ? 'desktop' : 'mobile';?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=5.0, user-scalable=yes">
<style>
html{}
body{
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.desktop{color:green;}
.mobile{color:red;}
</style>
</head>
<body>
<h1 class="<?php echo $width >= 769 ? 'desktop' : 'mobile';?>">
<?php echo $width >= 769 ? 'desktop' : 'mobile';?>
</h1>
</body>
</html>
<?php }?>
let data,
chart,
result = {longRate: [], shortRate: [], exchangeName: []}, // объявляем сразу как объект
options = { series: [], chart: {}, plotOptions: {}, xaxis: {}}; // тоже объявляем сразу как объект
fetch("https://fapi.coinglass.com/api/futures/longShortRate?symbol=BTC&timeType=3")
.then(response => response.json()
)
.then (data => {
console.log(data['data'][0]);
if(data['data'].length > 0){ // нужно проверить хотя бы так
for (i = 0; i < data['data'][0]['list'].length; i++) {
result.longRate[i] = data['data'][0]['list'][i]['longRate'];
result.shortRate[i] = data['data'][0]['list'][i]['shortRate'];
result.exchangeName[i] = data['data'][0]['list'][i]['exchangeName'];
}
checkSales(result); // вызываем проверку #sales (внутри then )
}else{
console.log('no data');
}
});
function checkSales(result){ // это теперь отдельная функция
if ($('#sales').length) {
options.series: [{ // без var
name: 'Лонг',
data: result.longRate, // < -- result['longRate']
}, {
name: 'Шорт',
data: result.shortRate, // < -- result['shortRate']
},
];
options.chart: {
id: 'longshortratio',
type: 'bar',
height: 350,
stacked: true,
stackType: '100%'
};
options.plotOptions: {
bar: {
horizontal: true,
},
};
options.xaxis: {
categories: result.exchangeName, // < -- result['exchangeName']
labels: {
formatter: function (val) {
return val
}
}
};
chart = new ApexCharts( // без var
document.querySelector("#sales"),
options
);
chart.render();
}
}
<span class="handle" >