douluan5738 2017-11-13 09:14
浏览 62
已采纳

如何增加div的scrolllspeed?

I am trying to make a sort of parallax webdesign. My question is, if someone knows how I can make the red div move faster. I think its in the formule but dont know sure. Maybe someone knows?

Here is my code: http://jsfiddle.net/PvVdq/

$(document).ready(function () {
var $horizontal = $('#horizontal');

$(window).scroll(function () {
    var s = $(this).scrollTop(),
        d = $(document).height(),
        c = $(this).height();

    scrollPercent = (s / (d - c));

    var position = (scrollPercent * ($(document).width() - $horizontal.width()));

    $horizontal.css({
        'left': position
    });
});

});

  • 写回答

2条回答 默认 最新

  • dopa53272 2017-11-13 09:18
    关注

    I'm not so sure about this. When I tried this one, it speeds up the movement of the red div

    $(document).ready(function () {
    var $horizontal = $('#horizontal');
    
    $(window).scroll(function () {
        var s = $(this).scrollTop(),
            d = $(document).height(),
            c = $(this).height();
    
        scrollPercent = (s / (d - c));
    
        var position = (scrollPercent * 10 * ($(document).width() - $horizontal.width()));
    
        $horizontal.css({
            'left': position
        });
    });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作