收獲到了什么?
- 定時(shí)器的使用方法
setInterval(函數(shù)蚊逢,時(shí)間)
使用之前可以把定時(shí)器封裝在一個(gè)變量里面 var timer = setInterval()
- 停止定時(shí)器的方法
clearInterval()
括號(hào)里面直接寫變量名稱就好了 clearInterval(timer)
- Math.random() 方法,只能隨機(jī)0-1之間的浮點(diǎn)數(shù)字
- Math.floor() 向下取整方法
Math.floor(Math.random() * 7)
這樣取的數(shù)字就是不小于7大于0的整數(shù)
- 昨天的項(xiàng)目做完了,最后一塊狀態(tài)切換的代碼沒有按照教程來,用的是自己的方法
- 用到了阻止事件冒泡方法
對(duì)于收獲的想法闲勺?
- 學(xué)習(xí)到了很多,基礎(chǔ)又扎實(shí)了一些
- 很有成就感
明天的打算扣猫?
- 繼續(xù)找JavaScript項(xiàng)目來做
- JavaScript 的鍵盤事件
- 用jQuery再把今天的項(xiàng)目寫一遍
項(xiàng)目的原js代碼:
window.onload = function(){
//拖曳效果
var otitle = document.getElementById("title"),
colse = document.getElementById("colse");
otitle.onmousedown = darg;
colse.onclick = function(){
document.getElementById("box").style.display = 'none';
}
//下拉效果
var obox = document.getElementById("select"),
omenu = document.getElementById("select_menu"),
olis = omenu.getElementsByTagName("li"),
otext = document.getElementById("select_text"),
oicon = document.getElementById("icon");
obox.onclick = function(event){
event = event || window.event;
if(event.stopPropagation){
event.stopPropagation();
}else{
event.cancelBubble;
}
omenu.style.display = 'block';
}
for(i = 0;i<olis.length;i++){
olis[i].onclick = function(){
var olis_text = this.innerText,
olis_class = this.className;
otext.innerText = olis_text;
oicon.className = "icon "+olis_class;
omenu.style.display = 'none';
}
}
document.onclick = function(){
omenu.style.display = 'none';
}
}
//單擊的時(shí)候觸發(fā)的操作
function darg(event){
var box = document.getElementById("box"),
x = event.clientX - box.offsetLeft,
y = event.clientY - box.offsetTop;
document.onmousemove = function(event){
fnMove(event,x,y);
}
document.onmouseup = function(){
document.onmousemove = null;
document.onmouseup = null;
}
}
//移動(dòng)的時(shí)候觸發(fā)的操作
function fnMove(event,postX,postY){
var box = document.getElementById("box"),
l = event.clientX - postX,
t = event.clientY - postY,
winW = document.documentElement.clientWidth,
winH = document.documentElement.clientHeight;
maxW = winW - box.offsetWidth,
maxH = winH - box.offsetHeight;
if(l<0){
l=0;
}else if(l>maxW){
l=maxW;
};
if(t<0){
t=0;
}else if(t>maxH){
t=maxH;
}
box.style.left = l + 'px';
box.style.top = t + 'px';
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者