带有文本的 jQuery 视差移动背景

标签 jquery css parallax

我正在尝试为一个小元素复制一些我非常喜欢的功能。

这是元素:https://en.playkot.com/

我已经使用以下代码使背景随鼠标移动而移动:

$(document).ready(function() {
    var movementStrength = 25;
    var height = movementStrength / $(window).height();
    var width = movementStrength / $(window).width();
    $("#top-image").mousemove(function(e){
        var pageX = e.pageX - ($(window).width() / 2);
        var pageY = e.pageY - ($(window).height() / 2);
        var newvalueX = width * pageX * -1 - 25;
        var newvalueY = height * pageY * -1 - 50;
        $('#top-image').css("background-position", newvalueX+"px     "+newvalueY+"px");

    });
});

我还希望文本随鼠标移动而移动。

我只是在徘徊是否有任何我可以使用的库来获得与上面示例相同的效果?

我的元素可以在这里查看:http://super-code.co.uk/test.php

最佳答案

您指的是哪个文本..??我看不到任何文本....IMG 中嵌入了文本“PLAYKOT”.. 你可以试试这个恐龙移动代码....

$('#dinosaur').on('mouseenter', function() {
  $(this).find('img').css('left', '50px');
}).on('mouseleave', function() {
  $(this).find('img').css('left', '0px');
});

关于带有文本的 jQuery 视差移动背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44539867/

相关文章:

jquery克隆div并将其附加到特定div之后

javascript - 单击jQuery时打开schuffle

jQuery 提取 div 内的文本,但不在 p 标签中

html - 内容不在 2 列页面上的正确列中

JavaScript 错误 : Object Required in ie6 & ie7

html - 如何将多个分区修复到屏幕顶部(视差滚动网站帮助)

javascript - 滚动时如何在水平条后面实现视差

javascript - 错误 : Object #<Object> has no method 'toUpperCase'

html - 下拉菜单和子菜单之间的差距

c++ - 视差映射 - GLSL- OpenGL