限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

javascript+css3鼠标悬停前置放大特效代码

所属分类: 网页特效-图片特效&上传    2024-02-26 09:18:21

javascript+css3鼠标悬停前置放大特效代码 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript+css3鼠标悬停前置放大特效代码(共8个文件)

    • index.html

使用方法

  • code
  • source
  1. var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}var $ = function $(selector) {return document.querySelector(selector);};
  2. var $$ = function $$(selector) {return document.querySelectorAll(selector);};
  3. var tick = 0;
  4. function lerp(n1, n2, speed) {
  5. return (1 - speed) * n1 + speed * n2;
  6. }
  7. function angle(from, to) {
  8. return Math.atan2(
  9. to[1] - from[1],
  10. to[0] - from[0]);
  11. }
  12. function distance(from, to) {
  13. return Math.sqrt(
  14. Math.pow(to[0] - from[0], 2),
  15. Math.pow(to[1] - from[1], 2));
  16. }
  17. function distNorm(from, to, xMax, yMax) {
  18. return Math.sqrt(
  19. Math.pow((to[0] - from[0]) / xMax, 2),
  20. Math.pow((to[1] - from[1]) / yMax, 2));
  21. }
  22. Array.prototype.lerp = function (target, speed) {var _this = this;
  23. this.forEach(function (n, i) {return _this[i] = lerp(n, target[i], speed);});
  24. };var
  25. Frame = function () {
  26. function Frame(node) {_classCallCheck(this, Frame);
  27. this.node = node;
  28. this.scale = 1;
  29. this.maxScale = 1.25;
  30. this.rotation = [0, 0, 0];
  31. this.translation = [0, 0, 0];
  32. this.center = [0, 0];
  33. this.target = [
  34. 0.5 * window.innerWidth,
  35. 0.5 * window.innerHeight];
  36. this.padding = [
  37. 0.5 * this.node.clientWidth,
  38. 0.5 * this.node.clientHeight];
  39. this.focus = false;
  40. this.mouseover = false;
  41. this.distance = 0;
  42. this.node.addEventListener('mousemove', this.hover.bind(this));
  43. this.node.addEventListener('mouseleave', this.hover.bind(this));
  44. this.setCenter();
  45. }_createClass(Frame, [{ key: 'setCenter', value: function setCenter()
  46. {
  47. var rect = this.node.getBoundingClientRect();
  48. this.center[0] = rect.left + this.padding[0];
  49. this.center[1] = rect.top + this.padding[1];
  50. return this;
  51. } }, { key: 'setTarget', value: function setTarget(
  52. target) {
  53. this.target[0] = target[0];
  54. this.target[1] = target[1];
  55. return this;
  56. } }, { key: 'setDistance', value: function setDistance()
  57. {
  58. this.distNorm = distNorm(this.center, this.target, window.innerWidth, 0.5 * window.innerHeight);
  59. return this;
  60. } }, { key: 'translate', value: function translate()
  61. {
  62. this.translation.lerp([
  63. 0,
  64. 0,
  65. this.mouseover ? 300 : 200 - this.distNorm * 400],
  66. 0.15);
  67. return this;
  68. } }, { key: 'rotate', value: function rotate()
  69. {
  70. var theta = angle(this.center, this.target);
  71. this.rotation.lerp([
  72. Math.sin(-theta) * 60 * this.distNorm,
  73. Math.cos(theta) * 90 * this.distNorm],
  74. 0.15);
  75. return this;
  76. } }, { key: 'update', value: function update()
  77. {
  78. this.node.style.transform = '\n\t\t\ttranslate3d(' +
  79. this.translation[0] + 'px,' + this.translation[1] + 'px,' + this.translation[2] + 'px) \n\t\t\trotateX(' +
  80. this.rotation[0] + 'deg) rotateY(' + this.rotation[1] + 'deg)\n\t\t';
  81. } }, { key: 'hover', value: function hover(
  82. e) {
  83. this.mouseover = e.type === 'mousemove';
  84. } }]);return Frame;}();var
  85. Gallery = function () {
  86. function Gallery() {_classCallCheck(this, Gallery);
  87. this.container = $('.gallery');
  88. this.center = [
  89. 0.5 * window.innerWidth,
  90. 0.5 * window.innerHeight];
  91. this.mouse = this.center.slice(0);
  92. this.target = this.mouse.slice(0);
  93. this.container.addEventListener('mousemove', this.hover.bind(this));
  94. this.container.addEventListener('mouseleave', this.hover.bind(this));
  95. window.addEventListener('resize', this.resize.bind(this));
  96. this.initFrames();
  97. this.update();
  98. }_createClass(Gallery, [{ key: 'initFrames', value: function initFrames()
  99. {var _this2 = this;
  100. this.frames = [];
  101. $$('.frame').forEach(function (node) {return _this2.frames.push(new Frame(node));});
  102. } }, { key: 'resize', value: function resize()
  103. {
  104. this.center = [
  105. 0.5 * window.innerWidth,
  106. 0.5 * window.innerHeight];
  107. this.frames.forEach(function (frame) {return frame.setCenter();});
  108. } }, { key: 'hover', value: function hover(
  109. e) {
  110. this.mouseover = e.type === 'mousemove';
  111. this.target[0] = e.clientX;
  112. this.target[1] = e.clientY;
  113. } }, { key: 'update', value: function update()
  114. {var _this3 = this;
  115. this.mouse.lerp(
  116. this.mouseover ? this.target : this.center,
  117. 0.125);
  118. this.frames.forEach(function (frame) {
  119. frame.setTarget(_this3.mouse).
  120. setDistance().
  121. translate().
  122. rotate().
  123. update();
  124. });
  125. this.container.style.perspectiveOrigin = this.mouse[0] + 'px 50%';
  126. window.requestAnimationFrame(this.update.bind(this));
  127. } }]);return Gallery;}();
  128. var gallery = new Gallery();
var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}var $ = function $(selector) {return document.querySelector(selector);};
var $$ = function $$(selector) {return document.querySelectorAll(selector);};
var tick = 0;

function lerp(n1, n2, speed) {
    return (1 - speed) * n1 + speed * n2;
}

function angle(from, to) {
    return Math.atan2(
    to[1] - from[1],
    to[0] - from[0]);

}

function distance(from, to) {
    return Math.sqrt(
    Math.pow(to[0] - from[0], 2),
    Math.pow(to[1] - from[1], 2));

}

function distNorm(from, to, xMax, yMax) {
    return Math.sqrt(
    Math.pow((to[0] - from[0]) / xMax, 2),
    Math.pow((to[1] - from[1]) / yMax, 2));

}

Array.prototype.lerp = function (target, speed) {var _this = this;
    this.forEach(function (n, i) {return _this[i] = lerp(n, target[i], speed);});
};var

Frame = function () {
    function Frame(node) {_classCallCheck(this, Frame);
        this.node = node;
        this.scale = 1;
        this.maxScale = 1.25;
        this.rotation = [0, 0, 0];
        this.translation = [0, 0, 0];
        this.center = [0, 0];
        this.target = [
        0.5 * window.innerWidth,
        0.5 * window.innerHeight];

        this.padding = [
        0.5 * this.node.clientWidth,
        0.5 * this.node.clientHeight];

        this.focus = false;
        this.mouseover = false;
        this.distance = 0;
        this.node.addEventListener('mousemove', this.hover.bind(this));
        this.node.addEventListener('mouseleave', this.hover.bind(this));
        this.setCenter();
    }_createClass(Frame, [{ key: 'setCenter', value: function setCenter()
        {
            var rect = this.node.getBoundingClientRect();
            this.center[0] = rect.left + this.padding[0];
            this.center[1] = rect.top + this.padding[1];
            return this;
        } }, { key: 'setTarget', value: function setTarget(
        target) {
            this.target[0] = target[0];
            this.target[1] = target[1];
            return this;
        } }, { key: 'setDistance', value: function setDistance()
        {
            this.distNorm = distNorm(this.center, this.target, window.innerWidth, 0.5 * window.innerHeight);
            return this;
        } }, { key: 'translate', value: function translate()
        {
            this.translation.lerp([
            0,
            0,
            this.mouseover ? 300 : 200 - this.distNorm * 400],
            0.15);
            return this;
        } }, { key: 'rotate', value: function rotate()
        {
            var theta = angle(this.center, this.target);
            this.rotation.lerp([
            Math.sin(-theta) * 60 * this.distNorm,
            Math.cos(theta) * 90 * this.distNorm],
            0.15);
            return this;
        } }, { key: 'update', value: function update()
        {
            this.node.style.transform = '\n\t\t\ttranslate3d(' +
            this.translation[0] + 'px,' + this.translation[1] + 'px,' + this.translation[2] + 'px) \n\t\t\trotateX(' +
            this.rotation[0] + 'deg) rotateY(' + this.rotation[1] + 'deg)\n\t\t';

        } }, { key: 'hover', value: function hover(
        e) {
            this.mouseover = e.type === 'mousemove';
        } }]);return Frame;}();var


Gallery = function () {
    function Gallery() {_classCallCheck(this, Gallery);
        this.container = $('.gallery');
        this.center = [
        0.5 * window.innerWidth,
        0.5 * window.innerHeight];

        this.mouse = this.center.slice(0);
        this.target = this.mouse.slice(0);
        this.container.addEventListener('mousemove', this.hover.bind(this));
        this.container.addEventListener('mouseleave', this.hover.bind(this));
        window.addEventListener('resize', this.resize.bind(this));
        this.initFrames();
        this.update();
    }_createClass(Gallery, [{ key: 'initFrames', value: function initFrames()
        {var _this2 = this;
            this.frames = [];
            $$('.frame').forEach(function (node) {return _this2.frames.push(new Frame(node));});
        } }, { key: 'resize', value: function resize()
        {
            this.center = [
            0.5 * window.innerWidth,
            0.5 * window.innerHeight];

            this.frames.forEach(function (frame) {return frame.setCenter();});
        } }, { key: 'hover', value: function hover(
        e) {
            this.mouseover = e.type === 'mousemove';
            this.target[0] = e.clientX;
            this.target[1] = e.clientY;
        } }, { key: 'update', value: function update()
        {var _this3 = this;
            this.mouse.lerp(
            this.mouseover ? this.target : this.center,
            0.125);

            this.frames.forEach(function (frame) {
                frame.setTarget(_this3.mouse).
                setDistance().
                translate().
                rotate().
                update();
            });
            this.container.style.perspectiveOrigin = this.mouse[0] + 'px 50%';
            window.requestAnimationFrame(this.update.bind(this));
        } }]);return Gallery;}();


var gallery = new Gallery();

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 图片特效&上传

jquery鼠标悬停图片向上/向下平滑滚动特效插件

一款鼠标悬停图片滚动器插件,鼠标悬停在图片区域上触发平滑缓慢的上下滚动特效。
  图片特效&上传
 2478  0

jquery响应式全屏滚动切换图片特效

一款全屏图片轮播插件,支持鼠标双击切换及键盘上下方向键操作。
  图片特效&上传
 4522  0

jquery手机端网页上传图片支持旋转裁剪功能插件

一款移动端图片上传插件,带图片旋转、图片裁剪、图片预览功能!
  图片特效&上传
 3457  0

js实现的电子邮件订阅表单提示特效代码

一个邮箱订阅表单特效,点击“订阅”按钮,显示隐藏的email文本框表单,输入提交后则显示感谢提示信息。
  图片特效&上传
 1299  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论