views:

592

answers:

1

Hey folks,

OK - I'll admit, I'm quite a beginner in this jQuery-department. I've probably made some amateur mistake, but hey, you gotta learn somewhere! :)

So I'm using jScrollPane: http://www.kelvinluck.com/assets/jquery/jScrollPane/jScrollPane.html

I want to use it style the scrollable area in my second column. Specifically, I would like to apply and format the scrollbars on the div #ajaxresults

My page is... rather jQuery heavy. I don't know if any variables are conflicting or something... in fact I really have no idea at all why this isn't working.

Take a look at my problematic page: http://furnace.howcode.com

In the header, I've set this to go:

    <!-- Includes for jScrollPane --> 
<script type="text/javascript" src="http://localhost:8888/js/jquery.mousewheel.min.js"&gt;&lt;/script&gt; 
<script type="text/javascript" src="http://localhost:8888/js/jScrollPane.js"&gt;&lt;/script&gt; 
<link rel="stylesheet" type="text/css" media="all" href="http://localhost:8888/stylesheets/jScrollPane.css" /> 
<script type="text/javascript"> 
$(function() {
    $('#ajaxresults').jScrollPane();
});
</script> 

(I've changed localhost on the server copy though)

Nothing ever seems to work with the #ajaxresults div. I've set, as the jScrollPane docs say, overflow:auto on it but still no luck. I find that when jScrollPane DOES seem to 'run' it just moves the div down about 100 pixels. Try it for yourself.

Perhaps someone could help? There's quite a few jQuery plugins there so I don't know if something's colliding/crashing etc...

Please note the site is still in development between myself and a friend, which explains the personal messages we submit to each other ('Hi Donnie!' etc. :D ). Also, when you view the page nothing may appear in the second column for a few seconds - it's just fetching the data via Ajax. So give it a little time.

Thanks very much!

Jack

A: 

After viewing your code, the first thing that strikes me is that you've placed JS code inside the "ajaxresults" div. Generally it's best to keep your code outside the target div. Place the empty div like so:

<div id="ajaxresults" class="scroll-pane"></div>

At the bottom and use jQuery to populate with something like .append() or .html(). There are lots of options. I'm sure there are more things I could knit pick but this seems to be first major change I'd suggest.

This might be a bit of a process.

Also, if you don't already have Firebug, I might suggest getting a copy. It can really be helpful in jQuery debugging.

gurun8
Thanks gurun8 - I'm currently inserting the content by using append() via an external Ajax controller. I've moved the div to the bottom but unfortunately am seeing no change. I've installed Firebug too and am taking a look, but if you have any further tips I'd really appreciate it! :)
Jack Webb-Heller
The fact that you're not getting much in the way of errors suggests that your syntax is correct but logic is wrong. Rule of thumb, I'd replace $(window).load(function() { with jQuery(document).ready(function() {
gurun8
Thanks buddy... I've gone through this loads but my Javascript still clearly isn't up to scratch. Changed all occurances of $(window).load to jQuery(document).ready, went through jScrollPane's troubleshooting, etc. etc. Do you have any final ideas? I'm starting to think about alternative ideas now. I haven't found any other equally good jQuery plugins to do the same thing.
Jack Webb-Heller
What are you really looking to achieve with jScrollPane? I'd be happy to help. If I were up to me, I redo the code structure dramatically but that's more of a coding technique/preference than a deal breaker bug. Can you get a stand alone jScrollPane sample working without all the other bells and whistles?
gurun8
I'm aiming to replace the default browser's scrollbars with something more sleek and in keeping with the theme, on the second column. I understand my code is pretty awful and quite messy but this is just a kind of 'first draft', I'm rewriting the entire site for Ajax. And yes, I got jScrollPane working by itself. There's just something stopping it working on this page. And what would you change about the code so 'dramatically'? Thanks for all your help and comments so far, by the way! :)
Jack Webb-Heller
No worries about the mess. It's in a development state. First and foremost, I'd separate logic from layout. Right now you've combined the two. Your jQuery and HTML should shouldn't be intertwined. It just causes problems that are unnecessary. Try to centralize all of your JS in one location, preferably at the top of your script.
gurun8