Reputation: 3074
I am trying to use tinyscrollbar (http://baijs.nl/tinyscrollbar/) with ajax loaded content. My original page has a div like this :
<div id="content-wrap" style="display:none;">
</div>
I use this function to make the ajax call :
$('#nav li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content-wrap').load(toLoad,showNewContent);
function showNewContent() {
$('#content-wrap').fadeIn(1000).css("display", "block");
$('#scrollbar1').tinyscrollbar();
$("#scrollbar1").tinyscrollbar_update();
}
The called content looks like this :
<div id="content">
<div id="scrollbar1">
<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>
<div class="viewport">
<div class="overview">
//some content
//some more content
</div></div></div>
</div>
But it doesnt work at all. What am I doing wrong ?
Upvotes: 1
Views: 1501
Reputation: 4585
I first created a file called content.htm like below
<html>
<body>
<div id="content">
<div id="scrollbar1">
<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>
<div class="viewport">
<div class="overview">
<p>//some content</p>
<p>//some content</p>
<p>//some content</p>
<p>//some content</p>
<p>//some content</p>
<p>//some content</p>
</div></div></div>
</div>
</body>
</html>
Then I created another file called test.htm like this
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://baijs.nl/tinyscrollbar/js/jquery.tinyscrollbar.js"></script>
<style>
#scrollbar1 { width: 520px; clear: both; margin: 20px 0 10px; }
#scrollbar1 .viewport { width: 500px; height: 200px; overflow: hidden; position: relative; }
#scrollbar1 .overview { list-style: none; position: absolute; left: 0; top: 0; }
#scrollbar1 .thumb .end,
#scrollbar1 .thumb { background-color: #003D5D; }
#scrollbar1 .scrollbar { position: relative; float: right; width: 15px; }
#scrollbar1 .track { background-color: #D8EEFD; height: 100%; width:13px; position: relative; padding: 0 1px; }
#scrollbar1 .thumb { height: 20px; width: 13px; cursor: pointer; overflow: hidden; position: absolute; top: 0; }
#scrollbar1 .thumb .end { overflow: hidden; height: 5px; width: 13px; }
#scrollbar1 .disable{ display: none; }
.noSelect { user-select: none; -o-user-select: none; -moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; }
</style>
</head>
<body>
<div id="content-wrap" style="display:none;">
</div>
<input type="button" value="Load Content" id="btnLoad"/>
<script language="javascript">
$('#btnLoad').click(function(){
var toLoad = "http://localhost/tinyscrollbar/Content.htm #content";
$('#content-wrap').load(toLoad,function(){
$('#content-wrap').fadeIn(1000).css("display", "block");
$('#scrollbar1').tinyscrollbar();
$("#scrollbar1").tinyscrollbar_update();
});
});
</script>
</body>
</html>
and it works fine for me.
I think you should narrow down your problem step by step. First check if the content is loading properly from the content div, then check the tinyscrollbar. I assume you are doing something wrong in the following code block
$('#nav li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content-wrap').load(toLoad,showNewContent);
Upvotes: 2