水平滚动jQuery在整个页面上工作 [英] horizontal scrolling jquery working on entire page

查看:66
本文介绍了水平滚动jQuery在整个页面上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在某个网站上工作.我需要在特定部分上水平滚动,因为我正在使用JinvertScroll jquery.当我运行该jquery的示例时,滚动已在整个页面上进行.我如何设置特定部分的滚动只是?我的意思是我该如何设置应该滚动的特定div?这是代码.

I am working on a site.I need horizontal scrolling on a particular section,for that i am using JinvertScroll jquery.When i run that jquery's example the scrolling is working on entire page.how can i set the scrolling for particular section only??I mean how can i set that particular div that should scroll?Here is the code.

     <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="css/example.css" />
</head>
<body>


   <section id="scrolll">
    <div class="middle scroll" style="border:solid red;backgroun:red">
        <img src="images/middle.png" alt="" />
    </div>



    <script type="text/javascript" src="../libs/jquery.min.js"></script>
    <script type="text/javascript" src="../src/jquery.jInvertScroll.js"></script>
    <script type="text/javascript">
    (function($) {
        var scrolll= document.getElementById('scrolll');
        var elem = $.jInvertScroll(['.scroll'],        // an array containing the selector(s) for the elements you want to animate
            {
            height: 600,                   // optional: define the height the user can scroll, otherwise the overall length will be taken as scrollable height
            onScroll: function(percent) {   //optional: callback function that will be called when the user scrolls down, useful for animating other things on the page
                console.log(percent-50);
            }
        });

        $(window).resize(function() {
          if ($(window).width() <= 768) {
            elem.destroy();
          }
          else {
            elem.reinitialize();
          }
        });
    }(jQuery));
    </script>
    </section>

    <section>
        <div style="border:solid orange;height:1000px"></div>
    </section>

</body>
</html>

推荐答案

您不需要插件.只需在要滚动的位置使用高度和溢出y即可

You don't need plugin for that. Just use height and overflow-y where you want a scroll

#scrolll{height: 600px;
  overflow-y: scroll;}

<section id="scrolll">
    <div class="middle scroll" style="border:solid red;backgroun:red">
        <img src="images/middle.png" alt="" />
    </div>


    </section>

    <section>
        <div style="border:solid orange;height:1000px"></div>
    </section>

这篇关于水平滚动jQuery在整个页面上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆