第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

為什么換了“touchstart”事件后,點擊就沒有效果了?

window.onload?=?function(){
	var?music?=?document.getElementById("music");
	var?audio?=?document.getElementsByTagName("audio")[0];

	//當音樂播放完停止的時候,自動停止光盤旋轉(zhuǎn)效果
	audio.addEventListener("ended",?function(event){
		//?this.style.animationPlayState?=?"paused";?安卓4.4以下和蘋果6不兼容
		//?this.style.webkitAnimationPlayState?="pasused";?蘋果6兼容,安卓不行
		music.setAttribute("class",?"");
	},false);

	//點擊音樂圖標,控制音樂播放器效果
	//?music.onclick?=?function(){
	//?	if(audio.paused){
	//?		audio.play();
	//?		//?this.style.animationPlayState?=?"paused";?安卓4.4以下和蘋果6不兼容
	//?		//?this.style.webkitAnimationPlayState?="pasused";?蘋果6兼容,安卓不行
	//?		this.setAttribute("class","play");?//沒辦法暫停在轉(zhuǎn)動的位置,而是回到初始位置
	//?	}else{
	//?		audio.pause();
	//?		this.setAttribute("class","");
	//?	}
	//?};

	//為了消除延遲,改用監(jiān)聽觸摸事件,監(jiān)聽手機屏幕觸摸
	music.addEventListener("touchstart",?function(event){
		if(audio.paused){
			audio.play();
			this.setAttribute("class","play");?
		}?else{
			audio.pause();
			this.setAttribute("class","");
		};
	},?false);
};


正在回答

3 回答

加一行代碼就可以了

$("body").on("touchstart", function(e) {

? ? ?// 判斷默認行為是否可以被禁用

? ? ?if (e.cancelable) {

? ? ? ? ?// 判斷默認行為是否已經(jīng)被禁用

? ? ? ? ?if (!e.defaultPrevented) {

? ? ? ? ? ? ?e.preventDefault();

? ? ? ? ?}

? ? ?}

?});

0 回復(fù) 有任何疑惑可以回復(fù)我~

我也是touchstart和touchmove不能觸發(fā),該怎么進行移動端開發(fā)?求助

0 回復(fù) 有任何疑惑可以回復(fù)我~

我今天折騰了一天,發(fā)現(xiàn)只有touchstart不行,touchend, touchmove, click這三個事件都可以順利觸發(fā),具體原理不明,我查了些資料,貌似click = touchstart[+touchmove]+tocuhend這些事件的合集

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

JS嘛霸哥

說錯了,touchmove也不行,應(yīng)該是為了保證用戶不是誤操作播放音樂,只有觸發(fā)touchend這個事件的時候才確認能夠播放,否則瀏覽器會阻止播放的調(diào)用吧。
2017-04-02 回復(fù) 有任何疑惑可以回復(fù)我~
#2

一神帶億坑 回復(fù) JS嘛霸哥

你是怎么解決“touchstart和touchmove不能觸發(fā)”這個問題的?
2017-04-28 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

為什么換了“touchstart”事件后,點擊就沒有效果了?

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號