日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

html5指南针,HTML5指北针(指南针)网页应用示例

發布時間:2023/12/8 HTML 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5指南针,HTML5指北针(指南针)网页应用示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

HTML

導入代碼模板:

H5指北針(指南針)演示程序

//計算屏幕寬度 高度

var pageWidth = window.innerWidth;

var pageHeight = window.innerHeight;

if (typeof pageWidth != "number") {

if (document.compatMode == "CSS1Compat") {

pageWidth = document.documentElement.clientWidth;

pageHeight = document.documentElement.clientHeight;

} else {

pageWidth = document.body.clientWidth;

pageHeight = document.body.clientHeight;

}

}

var zoom = 1;

//compass div 寬高

var paperWidth = 300;

var paperHeight = 300;

var crLong = 130 * zoom;

var crShort = 100 * zoom;

var cdiff = paperHeight / 2 - crLong;

var initX = (pageWidth - paperWidth) > 0 ? (pageWidth - paperWidth) / 2 : 0;

var initY = (pageHeight - paperHeight) > 0 ? (pageHeight - paperHeight) / 2 : 0;

document.getElementById("compass").style.marginTop = initY + "px";

document.getElementById("compass").style.marginLeft = initX + "px";

//創建畫布

var compassPaper = Raphael(initX, initY, paperWidth, paperHeight)

//畫園

compassPaper.circle(paperWidth / 2, paperHeight / 2, crLong).attr('fill', 'black');

var cross = compassPaper.set()

var crossStyle = {

stroke: 'white',

'stroke-width': 1

}

//指南針畫十字

var pathlineX = 'M' + (paperWidth / 2 - crShort / 2) + ' ' + (paperHeight / 2) + 'L' + (paperWidth / 2 + crShort / 2) + ' ' + (paperHeight / 2);

var pathlineY = 'M' + (paperWidth / 2) + ' ' + (paperHeight / 2 - crShort / 2) + 'L' + (paperWidth / 2) + ' ' + (paperHeight / 2 + crShort / 2);

var northline = 'M' + (paperWidth / 2) + ' ' + (paperHeight / 2 - crShort) + 'L' + (paperWidth / 2) + ' ' + (crLong - crShort);

cross.push(

compassPaper.path(pathlineX).attr(crossStyle),

compassPaper.path(pathlineY).attr(crossStyle)

)

//指北線

var northBar = compassPaper.path(northline).attr({

stroke: 'white',

'stroke-width': 4

})

var compass = compassPaper.set()

var strokeWidth

var billet

var degText

for (var i = 0; i < 360; i = i + 2) {

if (i % 30 == 0) {

strokeWidth = 2

degText = compassPaper.text(paperWidth / 2, (paperHeight / 2 - crShort) * 4 / 5, i).attr({

fill: 'white',

'font-size': '16rem'

}).transform('R' + i + ', ' + paperWidth / 2 + ', ' + paperHeight / 2)

degText.degPosition = i

compass.push(degText)

} else {

strokeWidth = 1

}

billet = compassPaper.path('M' + paperWidth / 2 + ' ' + (paperHeight / 2 - crShort) + 'L' + paperWidth / 2 + ' ' + (paperHeight / 2 - crShort + crShort / 5)).attr({

stroke: 'white',

'stroke-width': strokeWidth

}).transform('R' + i + ',' + paperWidth / 2 + ', ' + paperHeight / 2)

billet.degPosition = i

compass.push(

billet

);

}

['N', 'E', 'S', 'W'].forEach(function(direction, index) {

var directionText = compassPaper.text(paperWidth / 2, (paperHeight / 2 - crShort + crShort / 3), direction).attr({

fill: 'white',

'font-size': '20rem'

}).transform('R' + index * 90 + ', ' + (paperWidth / 2) + ',' + paperHeight / 2)

directionText.degPosition = index * 90

compass.push(directionText)

})

var redTriLine = 'M' + (paperWidth / 2) + ' ' + ((paperHeight / 2 - crLong) + cdiff / 2) + ' L' + (paperWidth / 2 - (paperHeight / 2 - crShort) / 4) + ' ' + (paperHeight / 2 - crShort) + ' L' + (paperWidth / 2 + (paperHeight / 2 - crShort) / 4) + ' ' + (paperHeight / 2 - crShort) + 'Z';

var redTriangle = compassPaper.path(redTriLine).attr({

fill: 'red',

'stroke-width': 0

})

redTriangle.degPosition = 0

compass.push(redTriangle)

var alphaText = compassPaper.text((paperWidth / 2), 440, '0°').attr({

fill: 'white',

'font-size': '30rem'

})

function throttle(method, delay, duration) {

var timer = null,

begin = new Date();

return function() {

var context = this,

args = arguments,

current = new Date();;

clearTimeout(timer);

if (current - begin >= duration) {

method.apply(context, args);

begin = current;

} else {

timer = setTimeout(function() {

method.apply(context, args);

}, delay);

}

}

}

function deviceOrientationListener(event) {

var alpha = event.webkitCompassHeading || event.alpha;

alphaText.attr({

text: parseInt(alpha) + '°'

});

var directionIndex

if (alpha > 337.5 || alpha < 22.5) {

directionIndex = 0

} else if (alpha > 45 - 22.5 && alpha < 45 + 22.5) {

directionIndex = 1

} else if (alpha > 90 - 22.5 && alpha < 90 + 22.5) {

directionIndex = 2

} else if (alpha > 135 - 22.5 && alpha < 135 + 22.5) {

directionIndex = 3

} else if (alpha > 180 - 22.5 && alpha < 180 + 22.5) {

directionIndex = 4

} else if (alpha > 225 - 22.5 && alpha < 225 + 22.5) {

directionIndex = 5

} else if (alpha > 270 - 22.5 && alpha < 270 + 22.5) {

directionIndex = 6

} else if (alpha > 315 - 22.5 && alpha < 315 + 22.5) {

directionIndex = 7

}

compass.forEach(function(item) {

item.transform('R' + (item.degPosition - alpha) + ',' + (paperWidth / 2) + ', ' + paperHeight / 2)

})

}

//手機是否支持重力事件

if (window.DeviceOrientationEvent) {

window.addEventListener('deviceorientation', throttle(deviceOrientationListener, 10, 30))

} else {

alert("Sorry your browser doesn't support Device Orientation");

}

總結

以上是生活随笔為你收集整理的html5指南针,HTML5指北针(指南针)网页应用示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 精品久久精品久久 | free性满足hd国产精品久 | 亚洲成人黄色在线 | 精品人妻无码一区二区 | 国产成人手机视频 | 久久久久国产精品一区 | 国产一线天粉嫩馒头极品av | 特级黄色一级片 | 久久都是精品 | 人成网站在线观看 | 变态视屏 | 国产精品天美传媒 | 亚洲色图国产精品 | 第一章激情艳妇 | 中文字幕永久 | 91精品国产色综合久久不8 | 日韩无套 | 韩国中文三级hd字幕 | 国产123区 | 97超碰伊人 | 极品色av| 伊伊综合网 | 成年人色片| 美女久久视频 | 久久久综合久久久 | 女优中文字幕 | 亚洲欧洲日本精品 | 性感美女视频一二三 | 永久免费在线观看视频 | 国产97色在线 | 国产 | 日本三级视频在线观看 | 免费观看av网站 | 久久久香蕉 | 国产一区二区网站 | 精品九九在线 | 秋霞欧美一区二区三区视频免费 | 精品久久久久久久中文字幕 | 狠狠鲁影院 | 亚洲毛片在线播放 | 一二三区免费 | 2025国产精品视频 | 成人91免费 | 亚洲第一色在线 | 男女啪啪国产 | 成人六区| 久久久久久成人 | 强睡邻居人妻中文字幕 | 精品国内自产拍在线观看视频 | 国产真实交换夫妇视频 | 亚洲一区二区三区影视 | 国产精品国产一区二区三区四区 | 久久久久久久一区二区三区 | 亚洲综合涩 | 999热精品| av不卡影院 | 亚洲成人免费在线观看 | 国产麻豆a毛片 | 中文字幕一区二区人妻在线不卡 | 人与动物2免费观看完整版电影高清 | 九色91 | 中文字幕亚洲在线观看 | 国产精品一区二区久久 | 亚洲一线av | 久久aaaa片一区二区 | 无码人妻精品一区二区三区蜜桃91 | 72种无遮挡啪啪的姿势 | 色资源在线 | 亚洲在线视频网站 | 蜜臀视频在线播放 | 成人两性视频 | 99热在| www.爱色av.com | 婷婷社区五月天 | 亚洲精品乱码久久久久久自慰 | 欧美久久久久久久久久久 | 天天舔天天干天天操 | 黄色日比视频 | 小泽玛利亚在线 | 亚洲 欧美 自拍偷拍 | 人体写真 福利视频 | 成人快手免费看片 | 91欧美视频 | 青青青国产视频 | 毛片a片免费观看 | 国产av无码专区亚洲av麻豆 | 国产三级午夜理伦三级 | 日日噜噜噜噜久久久精品毛片 | 亚洲免费视 | 亚洲制服丝袜诱惑 | 日韩精品一区二区三区av | www.成年人 | 一区两区小视频 | 亚洲精品123区 | 欧美又粗又长又爽做受 | 久久国内精品视频 | 亚洲黄色在线免费观看 | 日韩www.| av日韩在线播放 | 免费看的毛片 |