首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >鼠标移动使div移动平稳。

鼠标移动使div移动平稳。
EN

Stack Overflow用户
提问于 2017-04-15 17:03:29
回答 1查看 750关注 0票数 0

我正试图使我的div顺利倒转与“轻松”的效果。

当我悬停在div上时,我希望图像能够顺利地远离鼠标,就像他们在toyfight.co站点的第一部分中对这两个玩具的图片所做的那样。

我已经检查了他们的密码,却找不到答案。

你们中有人能提供吗?

我已经做了一个稍微粗糙的图像移动与下面的代码。也是一个链接到我在Codepen上的项目。(更小的这里)

这个插件帮助我实现了我的目标

http://www.jqueryscript.net/animation/jQuery-Plugin-For-3D-Perspective-Transforms-On-Mousemove-LogosDistort.html

代码语言:javascript
复制
<div class="section-0">
        <div class="phone-container" >
      <div class="phone-front" id="layer-one"></div>
    </div>
 </div>

<section class="section-1 parallax parallax-1">


  <div class="container" id="section-1">



         <div class="text-block animation-element">
        <h1>Gemaakt van het fijnste staal</h1>
        <p>"The volks is the rare kind of phone that I can recommend without reservations."<br> — The Verge</p>
      </div>
  </div>

</section>

JQUERY

代码语言:javascript
复制
  $.fn.smoothWheel = function () {
        //  var args = [].splice.call(arguments, 0);
        var options = jQuery.extend({}, arguments[0]);
        return this.each(function (index, elm) {

            if(!('ontouchstart' in window)){
                container = $(this);
                container.bind("mousewheel", onWheel);
                container.bind("DOMMouseScroll", onWheel);
                currentY = targetY = 0;
                minScrollTop = container.get(0).clientHeight - container.get(0).scrollHeight;
                if(options.onRender){
                    onRenderCallback = options.onRender;
                }
                if(options.remove){
                    log("122","smoothWheel","remove", "");
                    running=false;
                    container.unbind("mousewheel", onWheel);
                    container.unbind("DOMMouseScroll", onWheel);
                }else if(!running){
                    running=true;
                    animateLoop();
                }

            }
        });
    };
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-19 01:35:28

在第358行尝试使用.css()而不是.offset()

因此,来自:

代码语言:javascript
复制
$(target).offset({ top: y ,left : x });

至:

代码语言:javascript
复制
$(target).css({ top: y ,left : x });

总体效果要顺利得多。CodePen 这里.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43428818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档