javascript - 使用 jQuery 实现类似光标轨迹的效果

标签 javascript jquery

我想用 right:xxxPX 来制作绝对定位图像的动画。当动画正在进行时,我可以为其添加“轨迹”效果吗,就像 Windows 光标轨迹效果一样。

我可以用 jQuery 实现这种轨迹效果吗?

最佳答案

这应该有效:

var box = $('#box'),
    // Create some clones (these make up the trail)
    clones = $.map(Array(10), function(item, i){
        return box.clone().css('opacity', 1 / (i + 1)).hide().insertAfter(box);
    });

box.animate({
    top: 100,
    left: 200
}, {
    duration: 1000,
    step: function(now, fx) {

        // On each step, set a timeout for each clone,
        // making it move to the required position.

        var prop = fx.prop;

        $.each(clones, function(i, clone){
            clone = $(clone).show();
            setTimeout(function(){
                clone.css(prop, now);
            }, 50 * i);
        });

    }
});

演示: http://jsbin.com/ifobe3

关于javascript - 使用 jQuery 实现类似光标轨迹的效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2027765/

相关文章:

javascript - 选择 a 标签后的 "li"元素

php - 循环动态值中的表

javascript - jQuery:带有文本更改的背景幻灯片

php - 以编程方式检查图像元素颜色和颜色百分比

javascript - 如何在 React 中向 prop 添加新属性?

javascript - 尝试在 Vuejs 中过滤数组时出现问题?

javascript - ?p=index 或 ?p=about 在网站网址上

javascript - <script> 可以有哪些其他类型?

javascript - 如何选择没有属性的元素

jquery - 更改 CSS 以便图像填充 jQuery 选项卡