滚动到页面顶部
export const scrollToTop = () => {
const height = document.documentElement.scrollTop || document.body.scrollTop;
if (height > 0) {
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, height - height / 8);
}
}
滚动到页面底部
export const scrollToBottom = () => {
window.scrollTo(0, document.documentElement.clientHeight);
}
滚动到指定元素区域
export const smoothScroll = (element) => {
document.querySelector(element).scrollIntoView({
behavior: 'smooth'
});
};
获取可视窗口高度
export const getClientHeight = () => {
let clientHeight = 0;
if (document.body.clientHeight && document.documentElement.clientHeight) {
clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
}
else {
clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
}
return clientHeight;
}
获取可视窗口宽度
export const getPageViewWidth = () => {
return (document.compatMode == "BackCompat" ? document.body : document.documentElement).clientWidth;
}
打开浏览器全屏
export const toFullScreen = () => {
let element = document.body;
if (element.requestFullscreen) {
element.requestFullscreen()
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen()
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen()
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullScreen()
}
}
退出浏览器全屏
export const exitFullscreen = () => {
if (document.exitFullscreen) {
document.exitFullscreen()
} else if (document.msExitFullscreen) {
document.msExitFullscreen()
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen()
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen()
}
}悟空浏览器的秘密:如何轻松下载小说和视频?网页版入口大公开!
上面是“JavaScript开发小技巧之各种浏览器操作”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_1538.html
workflows工作流
树上一个快乐的猕猴桃ComfyUI工作流
一辆机器人虎狮高端混合动力车ComfyUI工作流
一只放屁虫甲虫ComfyUI工作流
一只可爱的快乐老鼠戴着帽子ComfyUI工作流
一个女孩骑着一辆生锈的现代摩托车
一个迷人的女人ComfyUI工作流
一个时间旅行女人的神秘剪影ComfyUI工作流
大黄蜂空中决战ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

jquery鼠标滑过图片边框特效(jquery.focus-follow插件)
纯css制作卡通头像(随鼠标转头)
利用js+css3做一个小鱼游泳特效
barcode条形码/qrcode二维码兼容所有浏览器(含ie6/ie7/ie8)
自动打字效果(惊喜在后面)
js导出excel插件(兼容mac电脑Numbers表格)
利用css绘画棋盘布局(象棋)
利用canvas画几个好玩的星云物种











