完整的html+css+javascript实现跟随鼠标移动显示选中效果

1,显示效果:

 

2,html结构

 1             <div class="process_list-lpu">
 2                 <div class="process_line"></div>
 3                 <div class="content_list">
 4                     <ul>
 5                         <li><a href="javascipt:;">End customer get product<b>1</b></a> </li>
 6                         <li><a href="javascipt:;">Log in EFOSE website and present installation or maintenance requirements <b>2</b></a></li>
 7                         <li><a href="javascipt:;">EFOSE prefer contact service point<b>3</b></a> </li>
 8                         <li style="margin-left:115px;"><a href="javascipt:;">Customer contact service point to get service<b>4</b></a> </li>
 9                         <li><a href="javascipt:;">Customer pays the bill directly or EFOSE pays the maintenance cost<b>5</b></a> </li>
10                     </ul>
11                     <div class="clear"></div>
12                 </div>
13             
14             </div>

3,主要的css样式

.line-lpu{ height:55px; position:relative; width:100%; overflow:hidden;}
    .line-lpu span{ width:43px; height:46px; background:url('https://www.efose.com/images/banners/lpu_03.png') no-repeat; position:absolute;top:0;}
    .border-lpu{border-bottom:1px  solid #959595; height:23px; }
     .join-lpu li{ width:19%; float:left; margin-right:8px;background:none; padding:0; }
    .join-lpu li a{ display:block; color:#606060; text-decoration:none; border:1px solid #959595; min-height:215px; padding:10px;position:relative; overflow:hidden;} 
    .join-lpu li a:hover{border:1px solid #337ab7;}
    .join-lpu li b{ font-size:60px; position:absolute; bottom:7px; right:-1px; font-style:italic; color:#c7c7c7;}
    .clear{clear:both;}
    .step-lpu span{ background:url('https://www.efose.com/images/banners/icon-lpu.png') no-repeat; display:block; width:75px; height:65px; margin-left:28px;}
    .step-lpu .icon0{ background-position:0 0;}
    .step-lpu .icon1{ background-position:0 -70px;}
    .step-lpu .icon2{ background-position:0 -140px;}
    .step-lpu .icon3{ background-position:0 -204px; height:58px; margin-bottom:7px;}
    .step-lpu .icon4{ background-position:0 -260px;}

4,JavaScript的编写

 1 <script type="text/javascript">
 2         //实例化animationHover对象
 3         window.onload = function(){
 4             var ah = new animationHover();  
 5             ah.init();
 6         }; 
 7         //初始化标签对象
 8         function animationHover(){
 9             this.step = document.getElementById('step');
10             this.stepLi = this.step.getElementsByTagName('li');
11             this.line = document.getElementById('line');
12             this.attr = null;
13             this.timer = null;
14             this.target = null;
15                             
16             }
17         //初始化事件
18         animationHover.prototype.init=function(){
19             This =this;
20             for(var i=0;i<this.stepLi.length;i++){
21                 this.stepLi[i].index=i;
22                 //给li标签绑定事件
23                 this.stepLi[i].οnmοuseοver=function(e){    
24                     var myIndex=this.index;
25                     This.onOver(This.line,(myIndex*162+55));
26                     };
27                 this.stepLi[i].οnmοuseοut=function(){            
28                    This.line.style.left=myIndex*162+55+'px';
29                     };    
30                 
31                 }
32             };
33         //定义鼠标经过的处理函数
34         animationHover.prototype.onOver=function(obj,target){
35             This=this;
36             clearInterval(this.timer);
37             This.target=target;
38             timer=setInterval(function(){
39                 var target=This.target; //停止的目标点
40                 var attrValue=parseInt(This.getStyle(obj,'left')); 
41                 var dx=target-attrValue; //距目标点的"路程"
42                 var speed=1/10*dx;
43                 speed=speed>0?Math.ceil(speed):Math.floor(speed); 
44                             //防止取整引起的抖动
45                 if(target==attrValue) clearInterval(timer); 
46                             //如果到达目标点,关闭定时器
47                 else{
48                     obj.style.left=attrValue+speed+'px';
49                 }
50                 },100);
51                                     
52             };
53         //获取当前标签对象的css属性值
54         animationHover.prototype.getStyle =function(obj,attr){                    
55             if(obj.currentStyle){                
56                 return obj.currentStyle[attr];
57             }else{
58                 return getComputedStyle(obj,false)[attr];
59             }
60             };    
61 
62             
63 
64     
65 </script>

 

转载于:https://www.cnblogs.com/liangsongbai/p/4866268.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现摄像头跟随鼠标移动效果,可以使用CSS的`transform`属性和JavaScript的`mousemove`事件来实现。 首先,在HTML中创建一个包含摄像头的容器元素,例如: ```html <div class="camera-container"> <video id="camera"></video> </div> ``` 然后,在CSS中设置容器元素的宽度和高度,以及摄像头的位置,例如: ```css .camera-container { position: relative; width: 640px; height: 480px; } #camera { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform: translate(-50%, -50%); } ``` 这里的关键是将摄像头的位置设置为绝对定位,并使用`transform: translate(-50%, -50%);`将其居中对齐。 接下来,在JavaScript中监听`mousemove`事件,并计算出鼠标相对于容器元素的位置,然后使用`transform: translate()`将摄像头移动到相应的位置。代码如下: ```javascript var cameraContainer = document.querySelector('.camera-container'); var camera = document.querySelector('#camera'); cameraContainer.addEventListener('mousemove', function(event) { var x = event.clientX / cameraContainer.offsetWidth; var y = event.clientY / cameraContainer.offsetHeight; camera.style.transform = 'translate(' + (x * 50 - 25) + '%, ' + (y * 50 - 25) + '%)'; }); ``` 这里使用`event.clientX`和`event.clientY`获取鼠标的坐标,然后将其除以容器元素的宽度和高度,得到相对于容器元素的位置比例。最后使用`transform: translate()`将摄像头移动到相应的位置。 完整的代码示例可以参考下面的代码片段: ``` .camera-container { position: relative; width: 640px; height: 480px; } #camera { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform: translate(-50%, -50%); } ``` ``` <div class="camera-container"> <video id="camera" autoplay></video> </div> <script> var cameraContainer = document.querySelector('.camera-container'); var camera = document.querySelector('#camera'); cameraContainer.addEventListener('mousemove', function(event) { var x = event.clientX / cameraContainer.offsetWidth; var y = event.clientY / cameraContainer.offsetHeight; camera.style.transform = 'translate(' + (x * 50 - 25) + '%, ' + (y * 50 - 25) + '%)'; }); navigator.mediaDevices.getUserMedia({ video: true }) .then(function(stream) { camera.srcObject = stream; }) .catch(function(error) { console.error(error); }); </script> ``` 注意,这里还使用了`navigator.mediaDevices.getUserMedia()`获取摄像头的视频流,并将其赋值给`<video>`元素的`srcObject`属性,以便显示摄像头的内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值