导航:首页 > 编程语言 > 鼠标跟随js实现

鼠标跟随js实现

发布时间:2024-04-02 13:07:29

『壹』 three.js如何让场景中模型跟随鼠标旋转呀

引入这个js <script src="../js/controls/OrbitControls.js"></script> 找你自己的路径哈,在threejs的库文件里面有的。然后在代码中加入
var controls = new THREE.OrbitControls(camera);//创建控件对版象 camera是你的相权机对象
controls.addEventListener('change', render);//监听鼠标、键盘事件
就可以随意旋转了。

『贰』 JS代码实现跟随鼠标移动的图片中细节问题求解,谢谢!

1.e就指的事件(event),其中就包括鼠标x y坐标(clientX clientY)。 e||window.event是为是兼容ie与ff。记住就好了,回当要取得事件时,答加上一个参数。尤其是在ff中,必须这样传事件,否则获取不到事件,而ie可以函数中直接用window.event获得事件。
2.这样实现是把他藏在左边很远的地方的了。也可以设置他的z-index,但是要指定它的position 为absolute,再指定z-index=-99; 或者直接另它的 display="none"。

『叁』 用js控制div跟随鼠标移动,鼠标点击后,鼠标离开,div留在当前点击的位置怎么做

你要的应该是拖拽效果,可以通过jq插件做

http://www.runoob.com/jqueryui/example-draggable.html

基本原理就是鼠标按下修改div的left和top(或者right/bottom)。鼠标离开不变。

<!DOCTYPEhtml>
<html>
<head>
<scriptsrc="/jquery/jquery-1.11.1.min.js">
</script>
<Style>
#test{
position:absolute;
}
</style>
<script>
$(document).mousedown(function(){
$(this).mousemove(function(e){
$("#test").css({"left":e.pageX+"px","top":e.pageY+"px"});
$(document).mouseup(function(){
$(this).unbind('mousemove');
})
})
})
</script>
</head>
<body>
<divid="test">ssssssssss</div>
</body>
</html>

『肆』 用JS制作跟随鼠标移动的方块

<!DOCTYPEhtml>
<html>
<head>
<metacharset=UTF-8>
<title>Yugi</title>
<style>
*{
margin:0;
padding:0;
}
</style>
<script>
varYugi=function(w,h,v)
{
this.w=w;
this.h=h;
this.v=v;
};

Yugi.prototype=newYugi;
Yugi.prototype.constructor=Yugi;

Yugi.pointToPoint=function(a,b){
returnMath.sqrt(Math.pow(a[0]-b[0],2)+Math.pow(a[1]-b[1],2));
}

Yugi.pointToAngle=function(origin,point){
varPI=Math.PI;
if(point[0]==origin[0]){
if(point[1]>origin[1])
returnPI*0.5;
returnPI*1.5
}elseif(point[1]==origin[1]){
if(point[0]>origin[0])
return0;
returnPI;
}
vart=Math.atan((origin[1]-point[1])/(origin[0]-point[0])*1);
if(point[0]>origin[0]&&point[1]<origin[1])
returnt+2*PI;
if(point[0]>origin[0]&&point[1]>origin[1])
returnt;
returnt+PI;
}

Yugi.prototype.create=function(e,_sX,_sY)
{
vardiv=document.createElement("div");
div.style.position="absolute";
div.style.cursor="pointer";
div.style.width=this.w+"px";
div.style.height=this.h+"px";
varL=e.clientX+_sX-this.w/2,T=e.clientY+_sY-this.h/2;
div.style.left=L+"px";
div.style.top=T+"px";
div.style.backgroundColor="red";
document.body.appendChild(div);
this.elem=div;
this.currPoint=[L,T];
};

Yugi.prototype.move=function(e,_sX,_sY)
{
varme=this,x=e.clientX+_sX-me.w/2,y=e.clientY+_sY-me.h/2;
varnewPoint=[x,y];
varsleep=20,speed=me.v/sleep;
me.interval&&clearInterval(me.interval);
me.interval=setInterval(function(){
varlen=Yugi.pointToPoint(me.currPoint,newPoint);
if(len<1){
clearInterval(me.interval);
me.interval=0;
}else{
varangle=Yugi.pointToAngle(me.currPoint,newPoint);
me.currPoint=[me.currPoint[0]+Math.cos(angle)*Math.min(len/2,speed),me.currPoint[1]+Math.sin(angle)*Math.min(len/2,speed)];
me.elem.style.left=me.currPoint[0]+'px';
me.elem.style.top=me.currPoint[1]+'px';
}
},sleep);
};

varyugi=newYugi(30,30,500);
document.onclick=function(e)
{
e=e||window.event;
var_sX=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft;
var_sY=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop;
varme=yugi;
if(!me.elem){
me.create(e,_sX,_sY);
}
else{
if(!me.interval){
varcloned=document.createElement("div");
cloned.innerHTML=me.elem.outerHTML;
document.body.appendChild(cloned.children[0]);
}
me.move(e,_sX,_sY);
}
};

document.oncontextmenu=newFunction("returnfalse");
</script>
</head>
<body></body>
</html>

『伍』 求鼠标移动上去就显示一张跟在鼠标的图片JS代码

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页特效|JsCode.cn|---跟随鼠标的图片</title>
<script LANGUAGE="javaScript">
var newtop=0
var newleft=0
if (navigator.appName == "Netscape") {
layerStyleRef="layer.";
layerRef="document.layers";
styleSwitch="";
}
else
{
layerStyleRef="layer.style.";
layerRef="document.all";
styleSwitch=".style";
}
function doMouseMove() {
layerName = 'iit'
eval('var curElement='+layerRef+'["'+layerName+'"]')
eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"')
eval('curElement'+styleSwitch+'.visibility="visible"')
eval('newleft=document.body.clientWidth-curElement'+styleSwitch+'.pixelWidth')
eval('newtop=document.body.clientHeight-curElement'+styleSwitch+'.pixelHeight')
eval('height=curElement'+styleSwitch+'.height')
eval('width=curElement'+styleSwitch+'.width')
width=parseInt(width)
height=parseInt(height)
if (event.clientX > (document.body.clientWidth - 5 - width))
{
newleft=document.body.clientWidth + document.body.scrollLeft - 5 - width
}
else
{
newleft=document.body.scrollLeft + event.clientX
}
eval('curElement'+styleSwitch+'.pixelLeft=newleft')
if (event.clientY > (document.body.clientHeight - 5 - height))
{
newtop=document.body.clientHeight + document.body.scrollTop - 5 - height
}
else
{
newtop=document.body.scrollTop + event.clientY
}
eval('curElement'+styleSwitch+'.pixelTop=newtop')
}
document.onmousemove = doMouseMove;
</script>
</head>

<body>
<!-- 以下代码是设定此页的鼠标样式代码 -->
<script language="javascript">
if (navigator.appName == "Netscape") {
}
else
{
document.write('<div ID=OuterDiv>')
document.write('<img ID=iit src="images/flag.gif" STYLE="position:absolute;TOP:5pt;LEFT:5pt;Z-INDEX:10;visibility:hidden;">')
document.write('</div>')
}
</script>
</body>

</html>

『陆』 用js控制div跟随鼠标移动,鼠标点击后,鼠标离开,div留在当前点击的位置怎么做

<!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8">
<title></title>
<styletype="text/css">
#box{
width:100px;
height:100px;
background-color:skyblue;
position:absolute;
}
</style>
<scripttype="text/javascript">
window.onload=function(){

varbox=document.getElementById("box");

varmove=function(event){
varx=event.pageX;
vary=event.pageY;

box.style.left=x-0.5*box.offsetWidth+"px";
box.style.top=y-0.5*box.offsetHeight+"px";

}

box.onclick=function(){
document.onmousemove=null;
}

box.ondblclick=function(){
document.onmousemove=move;
}

document.onmousemove=move;
}
</script>
</head>
<body>
<divid="box"></div>
</body>
</html>

阅读全文

与鼠标跟随js实现相关的资料

热点内容
什么软件能调节文件夹大小 浏览:478
win10的文件夹工具在哪个文件夹 浏览:554
消失的眼角膜完整版在线观 浏览:929
文件是怎么编号的 浏览:123
少林小子乌龙院免费观看 浏览:956
韩国电影失踪百度链接 浏览:140
二战苏联电影大片有哪些 浏览:620
识字不用教视频教程 浏览:141
桌面经常出现options文件 浏览:436
成龙可以复活的那个电影叫什么 浏览:986
ugt型刀怎么编程铣外圆 浏览:972
win10主题绅士 浏览:319
苹果7p的双镜头怎么用 浏览:439
enbx文件怎么打开 浏览:632
前戏特别长的电影 浏览:348
文件管理的五大职业是指什么 浏览:351
cad桌面应用程序 浏览:998
少女卖春电影 浏览:61
如何复制word整个文件 浏览:632

友情链接