来自 系统操作 2019-09-04 19:47 的文章
当前位置: 六合联盟网 > 系统操作 > 正文

jquery文字效果,基于jquery实现人物头像跟随鼠标

一款非常乖巧的人物头像跟随鼠标转动效果,在浏览器屏幕内,人物脸庞始终面向鼠标转动。其实现原理即同一张图片上作出人物上下左右不同面向的效果,利用JS调用背景图片的位置,以此实现人物“转脸”的jquery特效效果。
先给大家展示效果图,需要的朋友可以下载源码

jquery实现可旋转可拖拽的文字效果代码,jquery文字效果

本文实例讲述了jquery实现可旋转可拖拽的文字效果代码。分享给大家供大家参考,具体如下:

运行效果截图如下:

图片 1

具体代码如下:

<html>
 <head>
  <title>test</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript" >
   function scaleXBlock(blocker, scaleX){
    blocker.css({
     "-moz-transform": 'scaleX(' + scaleX + ')' ,
     "-webkit-transform": 'scaleX(' + scaleX + ')' ,
     "-o-transform": 'scaleX(' + scaleX + ')',
     "-ms-transform": 'scaleX(' + scaleX + ')',
     "transform": 'scaleX(' + scaleX + ')'
    });
   }
   function getPosition(event){
    return {
     x: parseInt(event.pageX || event.X),
     y: parseInt(event.pageY || event.Y)
    }
   }
   function cancelEvent(event){
    if(event.preventDefault ) {
     event.preventDefault(); 
    } else {
     //IE中阻止函数器默认动作的方式 
     event.returnValue = false; 
    }
    return false;
   }
   function stopDrag(blocker){
    blocker.data('draginfo', {
     isDrag: false
    });
    blocker.css('cursor', "arrow");
   }
   function drag(blocker){
    blocker.data('draginfo', {
     isDrag: false
    });
    blocker.css("position", "absolute");
    blocker.mousedown(function(event){
     event = event || window.event;
     var position = getPosition(event),
      offset = blocker.offset(),
      offsetX = position.x - parseInt(offset.left),
      offsetY = position.y - parseInt(offset.top);
     blocker.css('cursor', "move");
     blocker.data('draginfo', {
      isDrag: true,
      offsetX: offsetX,
      offsetY: offsetY 
     });
     cancelEvent(event);
    });
    blocker.mouseup(function(){
     stopDrag($(this));
    });
    $(document).mousemove(function(event){
     var dragInfo = blocker.data('draginfo');
     if(!dragInfo.isDrag) { 
      return;
     }
     event = event || window.event;
     var position = getPosition(event),
      x = position.x - dragInfo.offsetX,
      y = position.y - dragInfo.offsetY;
     blocker.css({
      "left": x + "px",
      "top": y + "px"
     });
     cancelEvent(event);
    }).mouseup(function(){
     stopDrag(blocker);
    });
   }
   function loopScaleXBlock(timeout, mode, blocker, scaleX){
    scaleXBlock(blocker, scaleX);
    setTimeout(function(){
     if(mode == "bigger") {
      if(scaleX < 1) {
       scaleX += 0.05;
      } else {
       mode = "smaller";
       scaleX = 1;
      }
     } else {
      if(scaleX > 0) {
       scaleX -= 0.05;
      } else {
       mode = "bigger";
       scaleX = 0.05;
      }
     }
     loopScaleXBlock(timeout, mode, blocker, scaleX);
    }, timeout);
   }
   function initDrag(){
    var dragList = $(".drag");
    for(var i=0,length=dragList.length; i<length; i++) {
     drag($(dragList[i]));
    }
   }
   function initScaleX(){
    var scaleXList = $(".scale");
    for(var i=0,length=scaleXList.length; i<length; i++) {
     loopScaleXBlock(10 * i + 10, "smaller", $(scaleXList[i]), 1);
    }
   }
   $(document).ready(function(){
    initScaleX();
    initDrag();
   });
  </script>
  <style type="text/css" >
   body 
   { 
    margin:0;
    background:black;
   }
   .block 
   { 
    position: absolute;
    text-align: center; 
    display: block; 
    width: 250px; 
    height: 250px; 
    background: #494949;
    font-size: 80px;
    color: #fff;
    line-height: 125px;
    text-shadow: 2px 2px 2px #fff;
    box-shadow: 2px 2px 2px #fff;
    cursor: pointer;
    opacity: 0.6;
    filter: alpha(opacity=60);
   }
   #scale
   {
    left:0;
    top:0;
   }
   #scale2
   {
    left:300px;
    top:0;
    background: #F2F2F2;
    color: orange;
   }
   #scale3
   {
    left:600px;
    top:0;
    background: orange;
    color: #494949;
   }
   #scale4
   {
    left:900px;
    top:0;
    background: green;
    color: gray;
   }
   #scale5
   {
    left:1200px;
    top:0;
    background: #494949;
    color: orange;
   }
  </style>
 </head>
 <body>
  <div class="block scale drag" id="scale">
   欢迎来看咧
  </div>
  <div class="block scale drag" id="scale2">
   欢迎来看咧
  </div>
  <div class="block scale drag" id="scale3">
   欢迎来看咧
  </div>
  <div class="block scale drag" id="scale4">
   欢迎来看咧
  </div>
  <div class="block scale drag" id="scale5">
   欢迎来看咧
  </div>
 </body>
</html>

更多关于jQuery特效相关内容感兴趣的读者可查看本站专题:《jQuery常见经典特效汇总》及《jQuery动画与特效用法总结》

希望本文所述对大家jQuery程序设计有所帮助。

图片 2

您可能感兴趣的文章:

  • 基于jquery实现人物头像跟随鼠标转动
  • jQuery实现转动随机数抽奖效果的方法
  • jQuery实现仿淘宝带有指示条的图片转动切换效果完整实例
  • jQuery实现可以控制图片旋转角度效果(附demo源码下载)
  • jQuery图片旋转插件jQueryRotate.js用法实例(附demo下载)
  • jQuery旋转木马式幻灯片轮播特效
  • jquery实现九宫格大转盘抽奖
  • jquery转盘抽奖功能实现
  • jQuery+css3实现转动的正方形效果(附demo源码下载)

本文实例讲述了jquery实现可旋转可拖拽的文字效果代码。分享给大家供大家参考,具...

效果演示     源码下载

具体实现过程不多说了,直接给大家贴代码了。

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>基于jquery实现人物头像跟随鼠标转动效果</title>
<link rel="stylesheet" type="text/css" href="css/jiaobenzhijia.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/team.css" media="screen">
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/lateral-eye.js"></script>
<script type="text/javascript" src="js/jquerytools.js"></script>
<script type="text/javascript" src="js/jquery.jkey-1.1.js"></script>
<script type="text/javascript" src="js/jquery.scrollTo-1.4.2-min.js"></script>
</head>
<body>
<div id="wrapper" class="wrapslide1 lateralSlide ">
 <div class="container">
  <h1 class="page-title">A passionate team</h1>
  <ul class="the-team clearfix">
   <li>
    <figure id="eye_andor_baranyi" class="eye">Andor</figure>
    <strong class="tooltip">Andor Baranyi<small>Development</small></strong> <strong class="name">Andor</strong> </li>
   <li>
    <figure id="eye_angela_borsan" class="eye">Angela</figure>
    <strong class="tooltip">Angela Borșan<small>Finance</small></strong> <strong class="name">Angela</strong> </li>
   <li>
    <figure id="eye_attila_szasz" class="eye">Attila</figure>
    <strong class="tooltip">Attila Szász<small>Development</small></strong> <strong class="name">Attila</strong> </li>
   <li>
    <figure id="eye_bogdan_haifa" class="eye">Bogdan</figure>
    <strong class="tooltip">Bogdan Haifa<small>Development</small></strong> <strong class="name">Bogdan</strong> </li>
   <li>
    <figure id="eye_bogdan_sala" class="eye">Bogdan</figure>
    <strong class="tooltip">Bogdan Sala<small>Development</small></strong> <strong class="name">Bogdan</strong> </li>
   <li>
    <figure id="eye_bogdan_stanescu" class="eye">Bogdan</figure>
    <strong class="tooltip">Bogdan Stănescu<small>Development</small></strong> <strong class="name">Bogdan</strong> </li>
   <li>
    <figure id="eye_bogus" class="eye">Bogus</figure>
    <strong class="tooltip">Bogus<small>Special Projects</small></strong> <strong class="name">Bogus</strong> </li>
   <li>
    <figure id="eye_botond_raduly" class="eye">Botond</figure>
    <strong class="tooltip">Botond Raduly<small>Development</small></strong> <strong class="name">Botond</strong> </li>
   <li>
    <figure id="eye_calin_tritean" class="eye">Călin</figure>
    <strong class="tooltip">Călin Tritean<small>Development</small></strong> <strong class="name">Călin</strong> </li>
   <li>
    <figure id="eye_ciprian_herman" class="eye">Ciprian</figure>
    <strong class="tooltip">Ciprian Herman<small>Development</small></strong> <strong class="name">Ciprian</strong> </li>
   <li>
    <figure id="eye_ciprian_morar" class="eye">Ciprian</figure>
    <strong class="tooltip">Ciprian Morar<small>Leadership</small></strong> <strong class="name">Ciprian</strong> </li>
   <!-- <li>
<figure id="eye_cristian_ban" class="eye">Cristian</figure>
<strong class="tooltip">Cristian Ban<small>Development</small></strong>
<strong class="name">Cristian</strong>
</li> -->
   <!--
<li>
<figure id="eye_cristian_buda" class="eye">Cristian</figure>
<strong class="tooltip">Cristian Buda<small>Development</small></strong>
<strong class="name">Cristian</strong>
</li>
-->
   <li>
    <figure id="eye_cristian_cojita" class="eye">Cristian</figure>
    <strong class="tooltip">Cristian Cojiță<small>Development</small></strong> <strong class="name">Cristian</strong> </li>
   <li>
    <figure id="eye_mesaros" class="eye">Cristian</figure>
    <strong class="tooltip">Cristian Mesaros<small>Development</small></strong> <strong class="name">Cristian</strong> </li>
   <li>
    <figure id="eye_cristian_zdrobe" class="eye">Cristian</figure>
    <strong class="tooltip">Cristian Zdrobe<small>Development</small></strong> <strong class="name">Cristian</strong> </li>
   <li>
    <figure id="eye_cristina_moldovan" class="eye">Cristina</figure>
    <strong class="tooltip">Cristina Moldovan<small>QA</small></strong> <strong class="name">Cristina</strong> </li>
   <li>
    <figure id="eye_csaba_tekse" class="eye">Csaba</figure>
    <strong class="tooltip">Csaba Tekse<small>Development</small></strong> <strong class="name">Csaba</strong> </li>
   <!--
<li>
<figure id="eye_daniel_cosman" class="eye">Daniel</figure>
<strong class="tooltip">Daniel Cosman<small>QA</small></strong>
<strong class="name">Daniel</strong>
</li>
-->
   <!-- <li>
<figure id="eye_daniel_zaremba" class="eye">Daniel</figure>
<strong class="tooltip">Daniel Zaremba<small>Development</small></strong>
<strong class="name">Daniel</strong>
</li> -->
   <!--    <li>
<figure id="eye_daria_petru" class="eye">Daria</figure>
<strong class="tooltip">Daria Nadina Petru<small>Management</small></strong>
<strong class="name">Daria</strong>
</li> -->
   <li>
    <figure id="eye_dory_ciceu" class="eye">Doru</figure>
    <strong class="tooltip">Doru Ciceu<small>Development</small></strong> <strong class="name">Doru</strong> </li>
   <li>
    <figure id="eye_dragos_bucevschi" class="eye">Dragoș</figure>
    <strong class="tooltip">Dragoș Bucevschi<small>Development</small></strong> <strong class="name">Dragoș</strong> </li>
   <li>
    <figure id="eye_erika_lacatus" class="eye">Erika</figure>
    <strong class="tooltip">Erika Lăcătuş<small>QA</small></strong> <strong class="name">Erika</strong> </li>
   <li>
    <figure id="eye_filip_chereches" class="eye">Filip</figure>
    <strong class="tooltip">Filip Cherecheș-Toșa<small>Leadership</small></strong> <strong class="name">Filip</strong> </li>
   <li>
    <figure id="eye_gabriel_lacatus" class="eye">Gabriel</figure>
    <strong class="tooltip">Gabriel Lăcătuş<small>Development</small></strong> <strong class="name">Gabriel</strong> </li>
   <li>
    <figure id="eye_ildiko_soos" class="eye">Ildikó</figure>
    <strong class="tooltip">Ildikó Soós<small>Development</small></strong> <strong class="name">Ildikó</strong> </li>
   <li>
    <figure id="eye_istvan_takacss" class="eye">István</figure>
    <strong class="tooltip">István Takács<small>Development</small></strong> <strong class="name">István</strong> </li>
   <li>
    <figure id="eye_jozsi" class="eye">Jozsi</figure>
    <strong class="tooltip">József Gergely<small>Development</small></strong> <strong class="name">Jozsi</strong> </li>
   <li>
    <figure id="eye_lavinia_mendrea" class="eye">Lavinia</figure>
    <strong class="tooltip">Lavinia Mendrea<small>Development</small></strong> <strong class="name">Lavinia</strong> </li>
   <li>
    <figure id="eye_levente_horvath" class="eye">Levente</figure>
    <strong class="tooltip">Levente Horváth<small>Development</small></strong> <strong class="name">Levente</strong> </li>
   <li>
    <figure id="eye_liviu_pogar" class="eye">Liviu</figure>
    <strong class="tooltip">Liviu Pogar<small>QA</small></strong> <strong class="name">Liviu</strong> </li>
   <li>
    <figure id="eye_marc" class="eye">Marc</figure>
    <strong class="tooltip">Marc Abrudan<small>Development</small></strong> <strong class="name">Marc</strong> </li>
   <li>
    <figure id="eye_maximilian_marele" class="eye">Maximilian</figure>
    <strong class="tooltip">Maximilian Marele<small>Design</small></strong> <strong class="name">Maximilian</strong> </li>
   <li>
    <figure id="eye_mihai_potcoava" class="eye">Mihai</figure>
    <strong class="tooltip">Mihai Potcoavă<small>Development</small></strong> <strong class="name">Mihai</strong> </li>
   <li>
    <figure id="eye_mihai_savu" class="eye">Mihai</figure>
    <strong class="tooltip">Mihai Savu<small>Development</small></strong> <strong class="name">Mihai</strong> </li>
   <li>
    <figure id="eye_mircea_baicu" class="eye">Mircea</figure>
    <strong class="tooltip">Mircea Baicu<small>Development</small></strong> <strong class="name">Mircea</strong> </li>
   <li>
    <figure id="eye_mircea_dragoi" class="eye">Mircea</figure>
    <strong class="tooltip">Mircea Drăgoi<small>Design</small></strong> <strong class="name">Mircea</strong> </li>
   <li>
    <figure id="eye_paul_abrudan" class="eye">Paul</figure>
    <strong class="tooltip">Paul Abrudan<small>Development</small></strong> <strong class="name">Paul</strong> </li>
   <li>
    <figure id="eye_radu_lucaciu" class="eye">Radu</figure>
    <strong class="tooltip">Radu Lucaciu<small>Development</small></strong> <strong class="name">Radu</strong> </li>
   <li>
    <figure id="eye_radu_pantea" class="eye">Radu</figure>
    <strong class="tooltip">Radu Pantea<small>QA</small></strong> <strong class="name">Radu</strong> </li>
   <li>
    <figure id="eye_sebastian_morar" class="eye">Sebastian</figure>
    <strong class="tooltip">Sebastian Morar<small>Development</small></strong> <strong class="name">Sebastian</strong> </li>
   <li>
    <figure id="eye_stefan_balan" class="eye">Ștefan</figure>
    <strong class="tooltip">Ștefan Bălan<small>Design</small></strong> <strong class="name">Ștefan</strong> </li>
   <li>
    <figure id="eye_tibor_fazakas" class="eye">Tibor</figure>
    <strong class="tooltip">Tibor Fazakas<small>QA</small></strong> <strong class="name">Tibor</strong> </li>
   <li>
    <figure id="eye_timi" class="eye">Timi</figure>
    <strong class="tooltip">Timi Fagadar<small>Development</small></strong> <strong class="name">Timi</strong> </li>
   <li>
    <figure id="eye_tudor_galanopulos" class="eye">Tudor</figure>
    <strong class="tooltip">Tudor Galanopulos<small>Development</small></strong> <strong class="name">Tudor</strong> </li>
   <li>
    <figure id="eye_victor_stegaru" class="eye">Victor</figure>
    <strong class="tooltip">Victor Stegaru<small>Development</small></strong> <strong class="name">Victor</strong> </li>
   <li>
    <figure id="eye_viorel_dram" class="eye">Viorel</figure>
    <strong class="tooltip">Viorel Dram<small>Development</small></strong> <strong class="name">Viorel</strong> </li>
   <li>
    <figure id="eye_zsolt_borbely" class="eye">Zsolt</figure>
    <strong class="tooltip">Zsolt Borbely<small>Development</small></strong> <strong class="name">Zsolt</strong> </li>
   <li>
    <figure id="eye_you" class="eye">You?</figure>
    <strong class="tooltip"><a href="//www.jb51.net/">Join us!</a><small>We have great coffee!</small></strong> <strong class="name">You?</strong> </li>
  </ul>
 </div>
</div>
</body>
</html>

以上代码就是基于jquery实现人物头像跟随鼠标转动,希望大家喜欢。

您可能感兴趣的文章:

  • 基于JQuery的一个简单的鼠标跟随提示效果
  • jQuery鼠标悬浮链接弹出跟随图片实例代码
  • jquery背景跟随鼠标滑动导航
  • jQuery+css3实现文字跟随鼠标的上下抖动
  • jQuery实现跟随鼠标运动图层效果的方法
  • jquery实现的提示浮层跟随鼠标移动
  • Jquery中国地图热点效果-鼠标经过弹出提示层信息的简单实例
  • jQuery实现鼠标跟随提示层效果代码(可显示文本,Div,Table,Html等)

本文由六合联盟网发布于系统操作,转载请注明出处:jquery文字效果,基于jquery实现人物头像跟随鼠标

关键词: