jquery+gsap实现鼠标悬浮css filter过滤器动画效果代码

代码语言:html

所属分类:悬停

代码描述:jquery+gsap实现鼠标悬浮css filter过滤器动画效果代码

代码标签: jquery gsap 鼠标 悬浮 css filter 过滤器 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">
  

  
  
  
  
<style>
body{
  background-color: #111;
}

*,
*:before,
*:after {
    box-sizing: border-box;
}

html,
html *,
body,
body * {
  cursor: none;
}

.work-item-container-wrapper {
  display: flex;
  width: 100%;
  height: 90vh;
  justify-content: center;
  align-items: center;
  align-content: center;
}

.work-item-container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.work-item-inner {
  overflow: hidden;
  width: 670px;
  height: 379px;
}

.rgbize {
  position: relative;
}

.rgbize img {
  position: absolute;
  display: block;
}

.rgb-first {
  opacity: 0;
/*   filter: contrast(1.2); */
  filter: hue-rotate(230deg);
  transition: 0.5s ease all;
  will-change: opacity, filter;
}

.rgb-second {
  opacity: 0;
/*   filter: sepia(80%); */
  filter: saturate(164%);
  transition: 0.7s ease all;
  will-change: opacity, filter;
}

.rgbize:hover .rgb-first{
  opacity: 0.8;
  will-change: opacity;
}

.rgbize:hover .rgb-second{
  opacity: 0.6;
  will-change: opacity;
}

.cursor-dot,
.cursor-dot-outline {
  pointer-events: none;
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
  z-index: 999;
}

.cursor-dot {
  width: 8px;
  height: 8px;
  background-color: #dedede;
}

.cursor-dot-outline {
  width: 40px;
  height: 40px;
  background-color: #181818;
}
</style>


</head>

<body >
  <div class="cursor-dot-outline"></div>
	<div class="cursor-dot"></div>
	<div class="work-item-container-wrapper">
		<div class="work-item-container">
			<div class="work-item-inner">
				<div class="work-item rgbize"> <img src="//repo.bfw.wiki/bfwrepo/image/62608bea4dd7d.png"> </div>
			</div>
		</div>

	</div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.9.1.js"></script>
      <script>
$(".work-item-inner").each(function () {
  var el = $(this).find('.rgbize');
  el.clone().appendTo(el).addClass('rgb-first');
  el.clone().appendTo(el).addClass('rgb-second');
});

var rect = $('.work-item-inner')[0].getBoundingClientRect();
var mouse = { x: 0, y: 0, moved: false };

$(".work-item-inner").mousemove(function (e) {
  mouse.moved = true;
  mouse.x = e.clientX - rect.left;
  mouse.y = e.clientY - rect.top;
});

function mm() {
  if (mouse.moved) {
    parallaxIt(".rgb-first", -80);
    parallaxIt(".rgb-second", -40);
  }
  mouse.moved = false;
}

// Ticker event will be called on every frame
gsap.ticker.add(mm);

function parallaxIt(target, movement) {
  gsap.to(target, 0.6, {
    x: (mouse.x - rect.width / 2) / rect.width * 30,
    y: (mouse.y - rect.height / 2) / rect.height * 70 });

}

$(window).on('.........完整代码请登录后点击上方下载按钮下载查看

网友评论0