繁体   English   中英

我如何使此滚动仅移动容器div而不是整个主体

[英]how do I make this scroll only shift the container div instead of the entire body

我正在使用UIWebView制作HTML5 iOS应用程序,并且正在尝试制作它,以便当用户浏览选项卡时,选项卡之间的水平滑动/滚动效果。 滑动/滚动效果有效,但它正在移动整个文档,而不只是容器div。 我想要的只是容器div中的元素滚动/滑动,而页脚保留在原位。

<body> 
    <div id="container"> 
        <div id="home-content">
            <div></div>
            <div>
                <div></div>
                <div></div>
            </div>
            <div></div>
        </div>
        <div id="gallery-content">
        </div>
        <div id="merch-content">
        </div>
        <div id="apps-content">
        </div>
        <div id="press-content">
        </div>
        <div id="footer"> 
            <ul class="nav"> 
                <li class="home active"><span><a href="#home-content" style="text-decoration:none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span></li> 
                <li class="gallery"><span><a href="#gallery-content" style="text-decoration:none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span></li> 
                <li class="merch"><span><a href="#merch-content" style="text-decoration:none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span></li> 
                <li class="apps"><span><a href="#apps-content" style="text-decoration:none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span></li> 
                <li class="press"><span><a href="#press-content" style="text-decoration:none;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></span></li> 
            </ul> 
        </div>
    </div> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>      
    <script src="js/jquery.easing.1.3.js" type="text/javascript" charset="utf-8"></script> 
    <script type="text/javascript"> 
        $(function() {
          $('ul.nav a').bind('click',function(event){
            var $anchor = $(this);
            $('html, body').stop().animate({
            scrollLeft: $($anchor.attr('href')).offset().left
          }, 1000);
          event.preventDefault();
          });
        });
    </script> 
</body> 

您的div#footer位于div#container

将其移到div#container ,然后将脚本更改为

$('#container').stop().animate({
    scrollLeft: $($anchor.attr('href')).offset().left
}, 1000);  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM