window.scrollTo({
top: 0,
left: 0,
behavior: 'instant'
});
iOS is a bit strange on that. You can use ontouchstart as follows:
<button class="button" ontouchstart>test</button>
Or the pseudo :target (works for <a> tags)
.button:target {
background-color: red; box-shadow: 0 5px #666; transform:
translateY(4px);
}const poem = "The Wide Ocean";
const author = "Pablo Neruda";
const favePoem = `My favorite poem is ${poem} by ${author}.`;
How to clear/disable js warnings console log error?
console.log = console.warn = console.error = () => {};
You can overwrite the console methods to make them no-op. Just make sure that you run this code before any other code.
-webkit-appearance:none; /*mac safari*/
-moz-appearance: none; /*firefox*/
function scrollToBottom() {
/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {...}display: flex;
/* establish flex container */
flex-direction: row;
/* default value; can be omitted */
flex-wrap: nowrap;
/* default value; can be omitted */
justify-content: space-between;
/* switched from default (flex-start, see below) */
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Old versions of Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
supported by Chrome, Edge, Opera and Firefox */
}
<div className='tagstitle'>
<img src={taginfo.img} className='tagimg'></img>
<div>{taginfo.name}</div>
</div>
.tagstitle{
align-items: center;
display: flex;
}
put css js into <body></body>
because ios browser will be white screen before loading the line into <body></body>
so, as fast as possible to load <body></body>
js:
document.documentElement.style = "opacity: 0;"; //hide all (document)
document.documentElement.style = "opacity: 1;";//display document
var request = new XMLHttpRequest();
request.open('GET', '/bar/foo.txt', false); // `false` makes the request synchronous
request.send(null);
if (request.status === 200) {
console.log(request.responseText);
}
@font-face {
Wrong
<meta property="og:image"
content="/test.png" />
Correct
<meta property="og:image"
content="https://abc.com/test.png" />
<img src="invalid_link"
onerror="this.onerror=null;this.src='https://placeimg.com/200/300/animals';"
>
.holds-the-iframe {
background:url(/tdnotes/gif/loading.gif) center center no-repeat;
background-size: 30px;
}
<iframe src="about:blank" class='holds-the-iframe' ></iframe>
function isInViewport(element) {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const formatDate = (date) => {
let formatted_date = date.getDate() + " " + months[date.getMonth()] + "," + date.getFullYear()
return formatted_date;
}
------------------------------------------------------------------
T"
toDateString() 格式化 JavaScript 資料此方法提取日期並以字串形式返回它。
var date = new Date();
result = date.toDateString();
console.log(result);
輸出:
"Thu Mar 18 2021"
toISOString() 格式化 JavaScript 資料它以 ISO 8601 格式返回包含日期/時間的字串。
var date = new Date();
result = date.toISOString();
console.log(result);
輸出:
"2021-03-18T19:11:35.957Z"
toLocaleString() 格式化 JavaScript 資料它將使用語言環境設定將日期物件轉換為字串。
var date = new Date();
result = date.toLocaleString();
console.log(result);
輸出:
"3/18/2021, 8:13:03 PM"
toLocaleTimeString() 格式化 JavaScript 資料它將日期物件轉換為字串,但只提取時間,使用本地設定。
var date = new Date();
result = date.toLocaleTimeString();
console.log(result);
輸出:
"8:14:22 PM"
dd-mm-yyyy 或 dd-mm-yyyy 及類似格式我們使用 getDate()、getMonth() 和 getFullYear() 方法來獲取日期的各個部分,並使用所需的符號和所需的順序將其連線起來。
例如,我們可以通過編寫下面的自定義函式來獲得 dd/mm/yyyy、dd-mm-yyyy 和 mm/yyyy 等任何我們喜歡的方式。
var date = new Date();
const formatDate = (date)=>{
let formatted_date = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear()
return formatted_date;
}
console.log(formatDate(date));
輸出:
"18-3-2021"
我們還可以在日期字串中放入月份名稱,例如 January,February,March。
var date = new Date();
const months = ["JAN", "FEB", "MAR","APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
const formatDate = (date)=>{
let formatted_date = date.getDate() + "-" + months[date.getMonth()] + "-" + date.getFullYear()
return formatted_date;
}
console.log(formatDate(date));
輸出:
"18-MAR-2021"
yyyy-mm-dd hh:mm:ss 和類似的格式我們使用所有方法 getDate(),getMonth() 和 getFullYear(),getHour(),getminutes(),getsecond() 來分別獲取日期和時間的各個部分,以及使用我們想要的符號和我們想要的順序將它們連線起來。
var date = new Date();
const formatDate = (current_datetime)=>{
let formatted_date = current_datetime.getFullYear() + "-" + (current_datetime.getMonth() + 1) + "-" + current_datetime.getDate() + " " + current_datetime.getHours() + ":" + current_datetime.getMinutes() + ":" + current_datetime.getSeconds();
return formatted_date;
}
console.log(formatDate(date));
輸出:
"2021-3-18 20:21:2"
< div > < img style = "vertical-align:middle" src = "https://via.placeholder.com/60x60" alt = "A gr...