script language="javascript"

10年積累的網(wǎng)站建設(shè)、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先建設(shè)網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有灌南免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
document.onmousemove = function(){
document.getElementById("out").innerText = event.srcElement.id
}
/script
div id="out"/div
div id="aa"aa/div
div id="bb"bb/div
一般來(lái)說(shuō),this指針指向當(dāng)前函數(shù)的所有者。
在這個(gè)例子中,this指向構(gòu)造函數(shù)Marray(也可以成為類);
this[i]相當(dāng)于Marray的一個(gè)屬性或者方法!
你要知道兩點(diǎn):1 、javascript里面所有元素都是對(duì)象,當(dāng)然包括函數(shù)也是;2、在Javascript里面,this指針代表的是執(zhí)行當(dāng)前代碼的對(duì)象的所有者。 根據(jù)兩個(gè)原則可以很容易判斷,比如第一個(gè),這個(gè)this的所有者是window 所以這個(gè)this.x=0;你可以理解成為window.x=0; 其他的你自己判斷吧
函數(shù)調(diào)用
function test(){
alert(1);
}
直接調(diào)用
test();
指定內(nèi)部this指針調(diào)用
(1)test.call(window);//執(zhí)行test函數(shù),將方法內(nèi)部this指向window
(2)test.apply(window);///執(zhí)行test函數(shù),將方法內(nèi)部this指向window
通過(guò)事件調(diào)用
window.onload = test;//當(dāng)頁(yè)面載入時(shí)調(diào)用
window.onerror = test;當(dāng)頁(yè)面發(fā)生錯(cuò)誤時(shí)調(diào)用
新建html復(fù)制黏貼運(yùn)行即可
html
head
title鼠標(biāo)跟隨效果/title
style type="text/css"
html {
overflow: hidden;
}
body {
position: absolute;
height: 100%;
width: 100%;
margin:0;
padding:0;
}
#screen {
background:#000;
position: absolute;
width: 100%;
height: 100%;
}
#screen span {
background: #fff;
font-size: 0;
overflow: hidden;
width: 2px;
height: 2px;
}
/style
script type="text/javascript"
var Follow = function () {
var $ = function (i) {return document.getElementById(i)},
addEvent = function (o, e, f) {o.addEventListener ? o.addEventListener(e, f, false) : o.attachEvent('on'+e, function(){f.call(o)})},
OBJ = [], sp, rs, N = 0, m;
var init = function (id, config) {
this.config = config || {};
this.obj = $(id);
sp = this.config.speed || 4;
rs = this.config.animR || 1;
m = {x: $(id).offsetWidth * .5, y: $(id).offsetHeight * .5};
this.setXY();
this.start();
}
init.prototype = {
setXY : function () {
var _this = this;
addEvent(this.obj, 'mousemove', function (e) {
e = e || window.event;
m.x = e.clientX;
m.y = e.clientY;
})
},
start : function () {
var k = 180 / Math.PI, OO, o, _this = this, fn = this.config.fn;
OBJ[N++] = OO = new CObj(null, 0, 0);
for(var i=0;i360;i+=20){
var O = OO;
for(var j=10; j35; j+=1){
var x = fn(i, j).x,
y = fn(i, j).y;
OBJ[N++] = o = new CObj(O , x, y);
O = o;
}
}
setInterval(function() {
for (var i = 0; i N; i++) OBJ[i].run();
}, 16);
}
}
var CObj = function (p, cx, cy) {
var obj = document.createElement("span");
this.css = obj.style;
this.css.position = "absolute";
this.css.left = "-1000px";
this.css.zIndex = 1000 - N;
document.getElementById("screen").appendChild(obj);
this.ddx = 0;
this.ddy = 0;
this.PX = 0;
this.PY = 0;
this.x = 0;
this.y = 0;
this.x0 = 0;
this.y0 = 0;
this.cx = cx;
this.cy = cy;
this.parent = p;
}
CObj.prototype.run = function () {
if (!this.parent) {
this.x0 = m.x;
this.y0 = m.y;
} else {
this.x0 = this.parent.x;
this.y0 = this.parent.y;
}
this.x = this.PX += (this.ddx += ((this.x0 - this.PX - this.ddx) + this.cx) / rs) / sp;
this.y = this.PY += (this.ddy += ((this.y0 - this.PY - this.ddy) + this.cy) / rs) / sp;
this.css.left = Math.round(this.x) + 'px';
this.css.top = Math.round(this.y) + 'px';
}
return init;
}();
/script/head
body
div id="screen"/div
script type="text/javascript"
new Follow('screen', {speed: 4,
animR : 2,
fn : function (i, j) {
return {
x : j/4*Math.cos(i),
y : j/4*Math.sin(i)
}
}})
/script/body
/html
分享文章:javascript指針,關(guān)于指針的代碼
網(wǎng)頁(yè)地址:http://chinadenli.net/article9/dsecdoh.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、Google、網(wǎng)站建設(shè)、商城網(wǎng)站、ChatGPT、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)