版头跟随鼠标移动效果

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>鼠标动版头</title>
    <style>
    .userDefinedArea {
        width: 1920px;
        margin: 0 auto
    }
    
    .user-yh-top {
        width: 990px;
        height: 565px;
        position: relative;
        margin: 0 auto;
        margin: 0 auto;
    }
    
    .user-yh-top p {
        position: absolute;
        top: 0;
        left: 50%;
    }
    
    .user-yh-top p.p1 {
        margin-left: -960px;
        width: 1920px;
        height: 100%;
    }
    
    .user-yh-top p.p2 {
        margin-left: -495px;
        width: 990px;
        height: 278px;
        z-index: 9999;
    }
    
    .user-yh-top p.p3 {
        margin-left: -495px;
        width: 990px;
        height: 284px;
        bottom: 0;
        top: auto;
    }
    
    .user-yh-top p.p4 {
        margin-left: -524px;
        width: 210px;
        height: 344px;
        top: 160px;
    }
    </style>
</head>

<body>
    <div class="mc" style=" min-height:0px;">
        <div class="j-module" module-function="autoCenter" module-param="{}">
            <div class="userDefinedArea">
                <div class="user-yh-top">
                    <p class="p1">![](http://upload-images.jianshu.io/upload_images/6449520-8e258859470e9c38.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</p>
                    <p class="p2" >![](http://upload-images.jianshu.io/upload_images/6449520-66b7f9353125ab08.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</p>
                    <p class="p3">![](http://upload-images.jianshu.io/upload_images/6449520-fdd5d7950d2b6f75.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</p>
                    <p class="p4">![](http://upload-images.jianshu.io/upload_images/6449520-f0c9ed18dd839fcc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</p>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript" src="http://t.moonbasa.com/Scripts/jquery-1.7.1.min.js?id=20141128"></script>
    <script>
    (function() {
        $.fn.mouseMove = function() {
            var container = $(this),
                height = container.offset().top,
                middle = $(window).width() / 2;
            container.find('p.p2').each(function() {
                var s = $(this);
                s.attr('offset-left', s.css('left') || 0);
                s.attr('offset-top', s.css('top') || 0);
                s.attr('offset-speed-x', Math.random() * 0.08);
                s.attr('offset-speed-y', Math.random() * 0.06);
            });
            $(document).mousemove(function(e) {
                if ($(document).scrollTop() <= height) {
                    var myMouseX = e.pageX - middle,
                        myMouseY = e.pageY - height / 2;
                    container.find('p.p2').each(function() {
                        var s = $(this);
                        s.css('left', parseInt(s.attr('offset-left')) + myMouseX * parseFloat(s.attr('offset-speed-x')));
                        s.css('top', parseInt(s.attr('offset-top')) + myMouseY * parseFloat(s.attr('offset-speed-y')));
                    });
                }
            });
        }
        $('.user-yh-top').mouseMove();
    })(jQuery);
    </script>
</body>

</html>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • document.onmousemove = function(ev){ var div = document.g...
    乍暖还寒2002阅读 2,607评论 0 0
  • 每个人都会有那么一刻,很想去纪念某种东西。 很久没有更文了。 协会招新结束了,一切仿佛尘埃落定,又好似才刚刚开始。...
    d29fdd1f6128阅读 1,729评论 1 4
  • 理论学家认为通过自己控制计算机给出的结果无比正确,实验学家认为自己手下的数据每一个点都是可变变量,对自己的数据充满...
    厘米元满阅读 1,414评论 0 0

友情链接更多精彩内容