【问题标题】:change from horiozntal scroll to vertical when mobile移动时从水平滚动变为垂直滚动
【发布时间】:2014-04-28 21:02:25
【问题描述】:

我的网站是响应式的。从笔记本电脑访问时,它具有水平导航,但从移动设备访问时,我想更改相同的滚动动画,但要垂直...

 <script>

$(function() {
    $('.nav a').bind('click',function(event){
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollLeft: $($anchor.attr('href')).offset().left
        }, 500);
        event.preventDefault();
    });
});


</script>

网站是 www.niklaskoskela.com

如果我需要提供其他任何东西,请告诉我。

亲切的问候

【问题讨论】:

    标签: jquery horizontal-scrolling vertical-scrolling


    【解决方案1】:

    像这样修改你的 .js:

    $(function() {
        $('.nav a').bind('click',function(event){
            var anchorOffset = $(this.hash).offset();
            $('html, body').stop().animate({
                scrollLeft: anchorOffset.left,
                scrollTop: anchorOffset.top // <- add this line
            }, 500);
            event.preventDefault();
        });
    });
    
    
    </script>
    

    并在 .css 中添加 媒体查询

    @media all and (max-width: 1024px){
      #one, #two, #three {
        float: none;
      }
    }
    

    【讨论】:

    • 我无法完成这项工作。滚动功能最终对它们中的任何一个都不起作用......我错过了什么吗?我有一个针对@media screen 的媒体查询和 (max-device-width: 960px 这与它有冲突吗?
    • 抱歉,我打错字了。应该是.hash 而不是.href 请检查working sample。请注意,我使用了display:inline-block 结构而不是float:left。如果有任何问题,请询问。关于您问题的第二部分:我没有注意到您的媒体查询。这算不上问题。您可以将float: none 移至您的地址。没关系。
    • 我愿意,怎么做?
    • :) 点击顶部箭头(在我的答案左侧)
    • 我需要 15 便士的声望才能“投票”,但我似乎没有……很抱歉
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 2021-11-13
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多