jScrollPane滚动条问题

发布于 2024-11-03 07:16:04 字数 1880 浏览 3 评论 0原文

我正在开发一个使用 Wordpress 作为 CMS 的网站,并且我想在我的网站的 div 内使用自定义滚动条。我一直在尝试使用 jScrollPane 插件,但无法使其正常工作。

主要代码在我的 header.php 文件中,并且有一个类 .scroll-pane header.php 中的相关代码是:

 <style type="text/css" id="page-css"> 
            .scroll-pane
                {
                    width: 100%;
                    height: 280px;
                    overflow: auto;
                }
        </style>
    <script src="<?php bloginfo('template_url'); ?>/js/jquery-1.3.2.min.js"></script>
    <link type="text/css" href="<?php bloginfo(template_url); ?>/style/jquery.jscrollpane.css" rel="stylesheet" media="all" />
    <script type="text/javascript" src="<?php bloginfo(template_url); ?>/js/jquery.mousewheel.js"></script>
    <script type="text/javascript" src="<?php bloginfo(template_url); ?>/js/jquery.jscrollpane.min.js"></script>

        <script type="text/javascript"> 
            var $j = jQuery.noConflict();
            $j(document).ready(function()
            {   
                $('.scroll-pane').jScrollPane({showArrows: true});
            });
        </script> 

page.php:

< div id="sign-right">

< div class="newsBox-padding">

< div class="scroll-pane newsBox"> WP loop goes here </div></div>


CSS:
.newsBox{height:280px; overflow: auto;}

我收到以下错误(被 firebug 捕获):

" $(".scroll-pane").jScrollPane is not a function
$('.scroll-pane').jScrollPane({showArrows: true}); "

我认为问题出在因此我尝试了来自各种帖子和论坛的一系列建议,包括:

$function(){ jQuery('.scroll-pane').jScrollPane({showArrows: true});

$function(){ $('.scroll-pane').jScrollPane({showArrows: true}); });

我检查了所有对外部文件的引用,并确保类的名称相同,它们似乎都是正确的。我也有一个精通代码的朋友看过它,但无济于事。

我真的很感谢你的帮助!

I am working on a site using Wordpress as a CMS, and I wanted to use a custom scroll bar inside a div on my website. I've been trying to use the jScrollPane plugin, but I'm having trouble getting it to work.

the main code is in my header.php file, and there is a class .scroll-pane the relevant code in header.php is:

 <style type="text/css" id="page-css"> 
            .scroll-pane
                {
                    width: 100%;
                    height: 280px;
                    overflow: auto;
                }
        </style>
    <script src="<?php bloginfo('template_url'); ?>/js/jquery-1.3.2.min.js"></script>
    <link type="text/css" href="<?php bloginfo(template_url); ?>/style/jquery.jscrollpane.css" rel="stylesheet" media="all" />
    <script type="text/javascript" src="<?php bloginfo(template_url); ?>/js/jquery.mousewheel.js"></script>
    <script type="text/javascript" src="<?php bloginfo(template_url); ?>/js/jquery.jscrollpane.min.js"></script>

        <script type="text/javascript"> 
            var $j = jQuery.noConflict();
            $j(document).ready(function()
            {   
                $('.scroll-pane').jScrollPane({showArrows: true});
            });
        </script> 

page.php:

< div id="sign-right">

< div class="newsBox-padding">

< div class="scroll-pane newsBox"> WP loop goes here </div></div>


CSS:
.newsBox{height:280px; overflow: auto;}

I get the following error (caught with firebug):

" $(".scroll-pane").jScrollPane is not a function
$('.scroll-pane').jScrollPane({showArrows: true}); "

I think the problem is in the function so I've tried a bunch of suggestions from various posts and forums including:

$function(){ jQuery('.scroll-pane').jScrollPane({showArrows: true});

$function(){ $('.scroll-pane').jScrollPane({showArrows: true}); });

I've checked all of my references to external files and made sure classes were named the same, they all seem to be right. And I've had a code savvy friend look at it too, to no avail.

I really appreciate your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

爱她像谁 2024-11-10 07:16:04

也许我在这里遗漏了一些东西,从未使用过 jscrollpane,但我没有看到你包括 jquery 本身。此外,您还可以调用 noconflict ,然后仍然在函数中使用 $ 。

Maybe I'm missing something here, never used jscrollpane, but I don't see you including jquery itself. Also you call noconflict and then still use $ in your function.

注定孤独终老 2024-11-10 07:16:04

我遇到这个问题是因为我加载了两次jquery。

Scrollpane 在以下情况下使用确实效果很好:

$(document).ready(function () {
    $('.scroll-pane').jScrollPane();
 });

另外,不要忘记在您应用的 div 中指定宽度和高度; IE。

<div class="scroll-pane" style="width: 200px; height: 100px;"></div>

I've had this problem because I was loading twice jquery.

Scrollpane does indeed work well when used in:

$(document).ready(function () {
    $('.scroll-pane').jScrollPane();
 });

Also don't forget to specify width and height in the div you're applying; ie.

<div class="scroll-pane" style="width: 200px; height: 100px;"></div>
吾家有女初长成 2024-11-10 07:16:04

我没有看到您包含最新的 jQuery,请尝试添加它。
要使用 google 主机添加最新的 jQuery:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" />

并尝试使用 Chrome 开发人员工具,然后使用资源选项卡,然后您将看到网络实际加载的 JS 文件。

你可以在我的博客上看到一篇关于这些滚动条的好文章: jQuery Scrollbars

同样像@kingjiv 所说,你使用 Conflict 然后使用 '$'。
尝试消除冲突并仅使用:

<script type="text/javascript"> $(function () {
  $('.scroll-pane').jScrollPane();
 });
<script> 

如果仍然不起作用,则 jScrollPane 会在 jQuery 之前加载。
要解决此问题,请尝试以下方法:

首先将您的 移动

<script type="text/javascript"> $(function () {
  $('.scroll-pane').jScrollPane();
 });
<script> 

结束标记之后的末尾。

如果仍然不起作用,请尝试使用当文档准备好时

<script type="text/javascript">
    $(document).ready(function () {
        $('.scroll-pane').jScrollPane();
    });
<script>

它必须起作用:)

I dont see that you include the latest jQuery, try adding it.
To add the latest jQuery using google host:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" />

And try using Chrome Developers Tools then Resources Tab, then you'll see which JS files the web actually loads.

you can see a nice post at my blog about those scroll bars: jQuery Scrollbars

Also like @kingjiv said, you use Conflict then '$'.
Try removing he Conflict and only use:

<script type="text/javascript"> $(function () {
  $('.scroll-pane').jScrollPane();
 });
<script> 

If it still doesn't work, the jScrollPane prolly loads before the jQuery does.
To fix this try those methods:

First moving you'r

<script type="text/javascript"> $(function () {
  $('.scroll-pane').jScrollPane();
 });
<script> 

To the end after the </body> Closing tag.

If still doesn't work try using When document ready

<script type="text/javascript">
    $(document).ready(function () {
        $('.scroll-pane').jScrollPane();
    });
<script>

It must work :)

断肠人 2024-11-10 07:16:04

我遇到了同样的问题,花了很长时间才解决。我只是找不到任何解决方案。

然后我遇到了这个 Wordpress 插件,名为:WP jScrollPane
我下载并安装了它。按照说明进行操作,就会出现自定义滚动条

所以对我来说这实际上是一个非常简单的解决方案。我太喜欢那个脚本了,以至于我完全忘记了 Wordpress 也有自己的插件。

无论如何,我不知道这对你是否有用,但它对我帮助很大。

I had the same problem and it took me ages to work it out. I just couldn't find any solution.

Then I came across this plugin for Wordpress named: WP jScrollPane.
I downloaded and installed it. Followed the instructions and the custom scrollbar appeared.

So for me that was actually a very simple solution. I was so into that script, that I totally forgot that Wordpress has its own plugins as well.

Anyway, I don't know if this is useful for you, but it helped me a lot.

梦幻之岛 2024-11-10 07:16:04

我厌倦了这个插件的问题。我工作了一天才让它运行起来。我发现它需要:

http://code.jquery.com/jquery-migrate-1.2.0.min.js

... 文件才能正常运行。所以它是一个老插件并且支持不是很好。

我对我的问题有一个非常简单的解决方案:):

div.scrollBar {
  width: 200px;
  height: 200px;
  overflow-y: scroll; /* has to be scroll, not auto */
  -webkit-overflow-scrolling: touch;
}

<div class="scrollBar">
<h3>Smooth</h3>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>

是工作示例:
http://jsfiddle.net/ghdcmsxx/

太棒了:D。它甚至针对触摸进行了优化。
哇。没有 jquery,只有很少的 css 和 html。我喜欢它。

I am tired of problems with this plugin. I worked for one day to get it to run. I found out, that it needs the:

http://code.jquery.com/jquery-migrate-1.2.0.min.js

... file, to run normally. So it is an old plugin and the support is not very good.

I have a very simple solution for my problem :) :

div.scrollBar {
  width: 200px;
  height: 200px;
  overflow-y: scroll; /* has to be scroll, not auto */
  -webkit-overflow-scrolling: touch;
}

and

<div class="scrollBar">
<h3>Smooth</h3>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>

Here is the working example:
http://jsfiddle.net/ghdcmsxx/

That´s great :D . And it´s even optimized for touch.
Wow. No jquery, only litte css and html. I love it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文