javascript特效问题 页面上有许多点一直跟随着鼠标指针的移动。如何实现这个这个效果.

html-css017

javascript特效问题 页面上有许多点一直跟随着鼠标指针的移动。如何实现这个这个效果.,第1张

新建html复制黏贴运行即可

<html>

<head>

<title>鼠标跟随效果</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=0i<360i+=20){

var O = OO

for(var j=10j<35j+=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 = 0i <Ni++) 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>

链接:https://pan.baidu.com/s/13NAnVf09BuG56XatvlnjhA

  提取码:7p6d

作品相关简介:两个性格迥异的女性却意外成了最好的姐妹——何希真、刘宛婷,他们同时喜欢上文棠生,但其实文棠生早就注意到刘宛婷,在好友希真的让步下,婉婷跟棠生进入交往,三人也形成亲密的三角关系,直到一场意外让宛婷发现原来她具有双重性征,而此刻她必须选择作为其中一个性别活下去。

CSS样式表中属性选择器四种格式属性选择器(AttributeSelectors),或许你不应该对属性选择器感到生疏,从本质上说,id跟类选择器其实就是属性选择器,只不过是选择了id或者类的值(value)而已。CSS样式表中属性选择器的格式是元素后跟中括号,中括号内带属性,或者属性表达式(不知道描述是否正确,自创的词),比如h1[title],h1[title="Logo"]等,你可以从我下面的论述中看到4种具体形式。1、简易属性选择器只顾其名不顾其值,这是CSS样式表中简易属性选择器的特点。h1[class]{color:silver}将会作用于任何带class的h1元素,不管class的值是什么。所以<h1class="hoopla">Hello</h1>、<h1class="severe">Serenity</h1>、<h1class="fancy">Fooling</h1>的h1都会受到这条规则的影响。当然,这个“属性”不仅仅是class或者id,可以是该元素所有合法属性,比如img的alt,这样img[alt]{cssdeclarationshere}将会作用于任何带有alt属性的img元素。那么a[href][title]{font-weight:bold}呢?聪明的你一定已经知道,这会作用于同时带href和title属性的a元素,比如<ahref=" http://www.mb5u.com/"title="mb5uHome"></a>。2、精确属性值选择器id和类本质上就是CSS样式表中的精确属性值选择器,没错,h1#logo等于h1[id="logo"]。如前所述,我们不要局限于id或者class,我们可以使用任何属性!例如a[href=" http://www.mb5u.com/"][title="W3CHome"]{font-size:200%}将会作用于<ahref=" http://www.mb5u.com/"title="mb5uHome"></a>。3、部分属性值选择器CSS样式表中部分属性值选择器如其名,只要属性值部分匹配(这里的部分,实际上要匹配整个单词)就会作用于该元素。让我们来看个例子:<pclasspclass="urgentwarning">Whenhandlingplutonium, caremustbetakentoavoidtheformationofacriticalmass.</p>p[class~="warning"]{font-weight:bold} 和p[class~="urgent"]{font-weight:bold} 中任何一条都可以让这个p的字体变粗。该选择器十分有用,比如你要样式化插图,其title中都含字符串”Figure”,如title="Figure5:xxx说明",则你可以使用img[title~="Figure"]。需要注重的是,如我第一句就强调的,你需要匹配的是整个单词,img[title~="Figure"]不会匹配title="Figure5:xxx说明"。另外,我做了个小小的测试,你把例子中的“Figure”改成“插图”,把img[title~="Figure"]改成img[title~="插图"],在Firefox中依然可以匹配,不管编码(encoding)是GB2312还是UTF-8。看来CSS对中文的支持还不赖。4、非凡属性选择器CSS样式表中这个选择器有点怪,它是这样工作的,举个例子比描述更轻易。*[lang|="en"]{color:white},这条规则(rule)将会选择属性lang的值en或者en-打头的元素。就是说,它可以匹配<h1lang="en">Hello!</h1>、<plang="en-us">Greetings!</p>和<divlang="en-au">G'day!</div>而不匹配<plang="fr">Bonjour!</p>和<h3lang="cy-en">Jrooana!</h3>。