简单视觉差效果

来自 http://sports.qq.com/isocce/2016eurocup/

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>简单视觉差效果</title>
    <style>
        body {
            text-align: center;
            background: url(http://mat1.gtimg.com/sports/2016ouzhoubei/images/mainbg.jpg) center top no-repeat;
        }
        .parallax-wrapper {
            position: relative;
            width: 1240px;
            height: 200px;
            margin: 0 auto;
        }
        .parallax-wrapper img {
            position: absolute;
        }
    </style>
</head>
<body>
    
    <div class="parallax-wrapper">
        < img id="parallax-star" src="http://mat1.gtimg.com/sports/2016ouzhoubei/images/star1.png" alt="" style="top: 30px; left: 660px;">
        < img id="parallax-football" src="http://mat1.gtimg.com/sports/2016ouzhoubei/images/football1.png" alt="" style="top: 30px; left: 690px;">
    </div>
    
    <h2>鼠标移动查看效果</h2>
    <p>
        图片素材均来自
        <a href="http://sports.qq.com/isocce/2016eurocup/" target="_blank">http://sports.qq.com/isocce/2016eurocup/</a>
    </p>

<script>
    var $ = function (id) {
        return document.getElementById(id);
    };
    var star = $('parallax-star');
    var football = $('parallax-football');
    
    /**
     * 每日一题
     * 根据鼠标在window窗口的相对位置关系修改重叠图片的定位,实现视觉差效果
     */
    document.addEventListener('mousemove', function (e) {
        var left = e.clientX;   // 鼠标位置横坐标
        var top = e.clientX;    // 鼠标位置纵坐标
        var width = window.innerWidth;  // 屏幕宽度
        var height = window.innerHeight;// 屏幕高度

        // TODO 
        // 同时修改两个图片的位置偏移, 实现偏移不一致, 从而实现视觉差
        star.style.cssText = '';    // 修改star 的位置
        football.style.cssText = '';  // 修改football 位置
    });
</script>
</body>
</html>

参考: http://runjs.cn/detail/vzbfnusy

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 北京时间10月2日,据《圣何塞水星新闻》报道,昨天勇士与掘金的季前赛开始之前,4届最佳防守球员本-华莱士把上赛季的...
    coco9981阅读 570评论 0 1
  • 北京时间10月1日,2017-18赛季季前赛揭幕战今天正式打响,金州勇士队主场以102比108不敌胜丹佛掘金。不过...
    coco9981阅读 418评论 0 2
  • 如果你是影视剧迷,稍一观察就会发现,今年高口碑的影视剧可谓是一部接一部,前有《人民的名义》、《欢乐颂》,后有《我的...
    coco9981阅读 476评论 0 0
  • title: 二层发现date: 2016-04-10 10:45tags: kali渗透测试 主动信息收集 0x...
    曼路x_x阅读 1,550评论 0 2
  • 长夏的暑气渐起 身体变得倦重 在操场上奔跑的身影愈渐缓慢 高温、潮湿的空气中氧气变得稀薄 连呼吸都有些困难 大脑在...
    刺猬纤森阅读 251评论 0 0