Здравствуйте, все понятно... но сайт в разработке и тестируется на локальном сервере, так что к сожалению пока нет возможности, как все обстоит на самом деле
Имеется страница и html kod такой:
Код:
<div id="slider">
<ul class="nav">
<li><a href="#" class="selected">Сраница 1</a></li>
<li><a href="#">Страница 2</a></li>
<li><a class="last "href="#">Страница 3</a></li>
</ul>
<div class="scroll">
<div class="content">
<div class="panel"><!-- Содержимое страницы --></div>
</div> <!-- content ends -->
</div> <!-- scroll ends -->
</div> <!-- slider ends -->
Код jQuery:
Код:
// when the DOM is ready...
$(document).ready(function () {
var $panels = $('#slider .content > div');
var $container = $('#slider .content');
// if false, we'll float all the panels left and fix the width
// of the container
var horizontal = true;
// float the panels left if we're going horizontal
if (horizontal) {
$panels.css({
'float' : 'left',
'position' : 'relative' // IE fix to ensure overflow is hidden
});
// calculate a new width for the container (so it holds all panels)
$container.css('width', $panels[0].offsetWidth * $panels.length);
}
// collect the scroll object, at the same time apply the hidden overflow
// to remove the default scrollbars that will appear
var $scroll = $('#slider .scroll').css('overflow', 'hidden');
// apply our left + right buttons
$scroll
.before('') // <img class="scrollButtons left" src="" />
.after(''); // <img class="scrollButtons right" src="" />
// height of nav selection
heights=[];
$('#slider .content > div').each(function(index){heights.push($(this).height());});
$('#slider .clone').live('click', function(e){
$('#slider .nav').find('a').eq($('#slider .nav').find('a').index(e.target)%heights.length).trigger('click');
return false;
});
$('#slider .nav').find('a').click(function(e){
$('.scroll').height(heights[$('#slider .nav').find('a').index(e.target)%heights.length]);
});
// handle nav selection
function selectNav() {
$(this)
.parents('ul:first')
.find('a')
.removeClass('selected')
.end()
.end()
.addClass('selected');
$(".clone").remove();
$(".nav").clone().addClass("clone").insertAfter(".scroll");
}
$('#slider .nav').find('a').click(selectNav);
// go find the nav link that has this target and select the nav
function trigger(data) {
var el = $('#slider .nav').find('a[href$="' + data.id + '"]').get(0);
selectNav.call(el);
}
if (window.location.hash) {
trigger({ id : window.location.hash.substr(1) });
} else {
$('ul.nav a:first').click();
}
// offset is used to move to *exactly* the right place, since I'm using
// padding on my example, I need to subtract the amount of padding to
// the offset. Try removing this to get a good idea of the effect
var offset = parseInt((horizontal ?
$container.css('paddingTop') :
$container.css('paddingLeft'))
|| 0) * -1;
var scrollOptions = {
target: $scroll, // the element that has the overflow
// can be a selector which will be relative to the target
items: $panels,
nav: '.nav a',
// selectors are NOT relative to document, i.e. make sure they're unique
prev: 'img.left',
next: 'img.right',
// allow the scroll effect to run both directions
axis: 'xy',
onAfter: trigger, // our final callback
offset: offset,
// duration of the sliding effect
duration: 500,
// easing - can be used with the easing plugin:
// http://gsgd.co.uk/sandbox/jquery/easing/
easing: 'swing'
};
// apply serialScroll to the slider - we chose this plugin because it
// supports// the indexed next and previous scroll along with hooking
// in to our nav.
$('#slider').serialScroll(scrollOptions);
// now apply localScroll to hook any other arbitrary links to trigger
// the effect
$.localScroll(scrollOptions);
// finally, if the URL has a hash, move the slider in to position,
// setting the duration to 1 because I don't want it to scroll in the
// very first page load. We don't always need this, but it ensures
// the positioning is absolutely spot on when the pages loads.
scrollOptions.duration = 1;
$.localScroll.hash(scrollOptions);
});
// jQuery.ScrollTo 1.3.3 http://flesler.blogspot.com
(function( $ ){
var $scrollTo = $.scrollTo = function( target, duration, settings ){
$scrollTo.window().scrollTo( target, duration, settings );
};
$scrollTo.defaults = {
axis:'y',
duration:1
};
//returns the element that needs to be animated to scroll the window
$scrollTo.window = function(){
return $( $.browser.safari ? 'body' : 'html' );
};
$.fn.scrollTo = function( target, duration, settings ){
if( typeof duration == 'object' ){
settings = duration;
duration = 0;
}
settings = $.extend( {}, $scrollTo.defaults, settings );
duration = duration || settings.speed || settings.duration; //speed is still recognized for backwards compatibility
settings.queue = settings.queue && settings.axis.length > 1; //make sure the settings are given right
if( settings.queue )
duration /= 2; //let's keep the overall speed, the same.
settings.offset = both( settings.offset );
settings.over = both( settings.over );
return this.each(function(){
var elem = this, $elem = $(elem),
t = target, toff, attr = {},
win = $elem.is('html,body');
switch( typeof t ){
case 'number': //will pass the regex
case 'string':
if( /^([+-]=)?\d+(px)?$/.test(t) ){
t = both( t );
break; //we are done
}
t = $(t,this); // relative selector, no break!
case 'object':
if( t.is || t.style ) //DOM/jQuery
toff = (t = $(t)).offset(); //get the real position of the target
}
$.each( settings.axis.split(''), function( i, axis ){
var Pos = axis == 'x' ? 'Left' : 'Top',
pos = Pos.toLowerCase(),
key = 'scroll' + Pos,
act = elem[key],
Dim = axis == 'x' ? 'Width' : 'Height',
dim = Dim.toLowerCase();
if( toff ){ //jQuery/DOM
attr[key] = toff[pos] + ( win ? 0 : act - $elem.offset()[pos] );
if( settings.margin ){ //if it's a dom element, reduce the margin
attr[key] -= parseInt(t.css('margin'+Pos)) || 0;
attr[key] -= parseInt(t.css('border'+Pos+'Width')) || 0;
}
attr[key] += settings.offset[pos] || 0; //add/deduct the offset
if( settings.over[pos] )//scroll to a fraction of its width/height
attr[key] += t[dim]() * settings.over[pos];
}else
attr[key] = t[pos]; //remove the unnecesary 'px'
if( /^\d+$/.test(attr[key]) ) //number or 'number'
attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) ); //check the limits
if( !i && settings.queue ){ //queueing each axis is required
if( act != attr[key] ) //don't waste time animating, if there's no need.
animate( settings.onAfterFirst ); //intermediate animation
delete attr[key]; //don't animate this axis again in the next iteration.
}
});
animate( settings.onAfter );
function animate( callback ){
$elem.animate( attr, duration, settings.easing, callback && function(){
callback.call(this, target);
});
};
function max( Dim ){
var el = win ? $.browser.opera ? document.body : document.documentElement : elem;
return el['scroll'+Dim] - el['client'+Dim];
};
});
};
function both( val ){
return typeof val == 'object' ? val : { top:val, left:val };
};
})( jQuery );
Так вот, если jQuery код удалить, то ваш скрипт работает прекрасно, а если нет
то ваш скрипт перестает работать, т.е. если на всех страницах 1 вкладка по умолчанию выделена, то на этой странице нет активной опции, как на изображении ниже:
Получается, что два скрипта используют один и тот же алгоритм и не могут работать вместе, а по отдельности все OK.
Пробовал уже по-разному реализовать, но пока не получается...