亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

我的照抄的代碼沒效果

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="js/zepto.min.js"></script>
<style>
? .touchPad{
? ? ?width:100%;
? ? ?height:500px;
? ? ?background: #ddd;
? ? ?font-size: 60px;
? }
? .ball{
? ? ?display: none;
? ? ?position: absolute;
? ? ?width: 25px;
? ? ?height:25px;
? ? ?border-radius: 15px;
? ? ?background: #4bcffe;
? ? ?top:0;
? ? ?left:0;
? }
? p{
? ? ?height:30px;

? }
</style>
<title>touch實例</title>
</head>

<body>
<p id="desc"></p>
<div id="touchPad" class="touchPad">觸屏板</div>
<div id="ball" class="ball"></div>
</body>
<script>
var touchpad = document.querySelector("#touchPad"),
? ball = document.querySelector("#ball"),
? desc = document.querySelector("#desc");

var toucjHandler = function(e){
? ? ?var type = e.type;
? ? ?if(type!=="touchend"){
? ? ? ? var pos = {
? ? ? ? ? ?x : e.touches[0].clientX,
? ? ? ? ? ?y : e.touches[0].clientY
? ? ? ? } ?
? ? ? ? ball.style.left = pos.x + "px";
? ? ? ? ball.style.top = pos.y + "px";
? ? ? ? desc.innerHTML = e.type + "(橫軸:" + pos.x + "縱軸:" + pos.y + ")";
? ? ?}else{
? ? ? ? desc.innerHTML = e.type;
? ? ?}
? ? ?switch(type){
? ? ? ? case 'touchstart':
? ? ? ? ? ?ball.style.display = 'block';
? ? ? ? ? ?break;
? ? ? ? case 'touchmove':
? ? ? ? ? ?event.preventDefault();
? ? ? ? ? ?break;
? ? ? ? case 'touchend':
? ? ? ? ? ?ball.style.display = 'none';
? ? ? ? ? ?break;
? ? ?}
? }
touchpad.addEventListener('touchstart',touchHandler);
touchpad.addEventListener('touchmove',touchHandler);
touchpad.addEventListener('touchend',touchHandler);
</script>
</html>

正在回答

1 回答

1. 文件未引入 : zepto.min.js引入了沒

2. 代碼錯誤 : 查找 toucjHandler 改成 touchHandler

這小錯誤 , 瀏覽器控制臺應該有提示的吧 , ?不過一天前的你應該已經解決了

所以 : 我是來混積分的

0 回復 有任何疑惑可以回復我~
#1

話1場告別 提問者

非常感謝!
2017-01-06 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

我的照抄的代碼沒效果

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號