编辑滑块中的javascript导航按钮(上一个和下一个)
我目前正在使用css设计hero slider的导航按钮,下面是我的代码,不过我想在www.bbc.co.uk上实现类似于slider的按钮。展开div并显示文本。谁能告诉我怎么做 这是我想要编辑的按钮的css编辑滑块中的javascript导航按钮(上一个和下一个),javascript,jquery,html,css,slider,Javascript,Jquery,Html,Css,Slider,我目前正在使用css设计hero slider的导航按钮,下面是我的代码,不过我想在www.bbc.co.uk上实现类似于slider的按钮。展开div并显示文本。谁能告诉我怎么做 这是我想要编辑的按钮的css .hero-carousel-nav li { position: absolute; bottom: 48px; right: 48px; list-style: none;
.hero-carousel-nav li {
position: absolute;
bottom: 48px;
right: 48px;
list-style: none;
}
.hero-carousel-nav li.prev {
left: 48px;
right: auto;
}
.hero-carousel-nav li a {
background: #FFF;
color: #fff;
border: none;
outline: none;
display: block;
float: left;
padding: 5px 20px;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
border-radius: 10px;
behavior: url(/assets/PIE.htc);
}
.hero-carousel-nav li a:hover {
background: #06C;
}
这是我的javascript,其中包括我想要编辑的上一个和下一个导航按钮的编码
jQuery.fn.heroCarousel = function(options){
options = jQuery.extend({
animationSpeed: 1000,
navigation: true,
easing: '',
timeout: 5000,
pause: true,
pauseOnNavHover: true,
prevText: 'Previous',
nextText: 'Next',
css3pieFix: false,
currentClass: 'current',
onLoad: function(){},
onStart: function(){},
onComplete: function(){}
}, options);
if(jQuery.browser.msie && parseFloat(jQuery.browser.version) < 7){
options.animationSpeed = 0;
}
return this.each(function() {
var carousel = jQuery(this),
elements = carousel.children();
currentItem = 1;
childWidth = elements.width();
childHeight = elements.height();
if(elements.length > 2){
elements.each(function(i){
if(options.itemClass){
jQuery(this).addClass(options.itemClass);
}
});
elements.filter(':first').addClass(options.currentClass).before(elements.filter(':last'));
var carouselWidth = Math.round(childWidth * carousel.children().length),
carouselMarginLeft = '-'+ Math.round(childWidth + Math.round(childWidth / 2) ) +'px'
carousel.addClass('hero-carousel-container').css({
'position': 'relative',
'overflow': 'hidden',
'left': '50%',
'top': 0,
'margin-left': carouselMarginLeft,
'height': childHeight,
'width': carouselWidth
});
carousel.before('<ul class="hero-carousel-nav"><li class="prev"><a href="#">'+options.prevText+'</a></li><li class="next"><a href="#">'+options.nextText+'</a></li></ul>');
var carouselNav = carousel.prev('.hero-carousel-nav'),
timeoutInterval;
if(options.timeout > 0){
var paused = false;
if(options.pause){
carousel.hover(function(){
paused = true;
},function(){
paused = false;
});
}
if(options.pauseOnNavHover){
carouselNav.hover(function(){
paused = true;
},function(){
paused = false;
});
}
function autoSlide(){
if(!paused){
carouselNav.find('.next a').trigger('click');
}
}
timeoutInterval = window.setInterval(autoSlide, options.timeout);
}
carouselNav.find('a').data('disabled', false).click(function(e){
e.preventDefault();
var navItem = jQuery(this),
isPrevious = navItem.parent().hasClass('prev'),
elements = carousel.children();
if(navItem.data('disabled') === false){
options.onStart(carousel, carouselNav, elements.eq(currentItem), options);
if(isPrevious){
animateItem(elements.filter(':last'), 'previous');
}else{
animateItem(elements.filter(':first'), 'next');
}
navItem.data('disabled', true);
setTimeout(function(){
navItem.data('disabled', false);
}, options.animationSpeed+200);
if(options.timeout > 0){
window.clearInterval(timeoutInterval);
timeoutInterval = window.setInterval(autoSlide, options.timeout);
}
}
});
function animateItem(object,direction){
var carouselPosLeft = parseFloat(carousel.position().left),
carouselPrevMarginLeft = parseFloat(carousel.css('margin-left'));
if(direction === 'previous'){
object.before( object.clone().addClass('carousel-clone') );
carousel.prepend( object );
var marginLeft = Math.round(carouselPrevMarginLeft - childWidth);
var plusOrMinus = '+=';
}else{
object.after( object.clone().addClass('carousel-clone') );
carousel.append( object );
var marginLeft = carouselMarginLeft;
var plusOrMinus = '-=';
}
if(options.css3pieFix){
fixPieClones(jQuery('.carousel-clone'));
}
carousel.css({
'left': carouselPosLeft,
'width': Math.round(carouselWidth + childWidth),
'margin-left': marginLeft
}).animate({'left':plusOrMinus+childWidth}, options.animationSpeed, options.easing, function(){
carousel.css({
'left': '50%',
'width': carouselWidth,
'margin-left': carouselPrevMarginLeft
});
jQuery('.carousel-clone').remove();
finishCarousel();
});
}
function fixPieClones(clonedObject){
var itemPieId = clonedObject.attr('_pieId');
if(itemPieId){
clonedObject.attr('_pieId', itemPieId+'_cloned');
}
clonedObject.find('*[_pieId]').each(function(i, item){
var descendantPieId = $(item).attr('_pieId');
$(item).attr('_pieId', descendantPieId+'_cloned');
});
}
function finishCarousel(){
var elements = carousel.children();
elements.removeClass(options.currentClass).eq(currentItem).addClass(options.currentClass);
options.onComplete(carousel, carousel.prev('.hero-carousel-nav'), elements.eq(currentItem), options);
}
if(jQuery.browser.msie){
carouselNav.find('a').attr("hideFocus", "true");
}
options.onLoad(carousel, carouselNav, carousel.children().eq(currentItem), options);
}
});
};
jQuery.fn.heroCarousel=函数(选项){
options=jQuery.extend({
动画速度:1000,
导航:对,
他说:,
超时:5000,
停顿:是的,
pauseOnNavHover:对,
prevText:“上一个”,
下一步:“下一步”,
css3pieFix:false,
currentClass:'当前',
onLoad:function(){},
onStart:function(){},
onComplete:函数(){}
},选项);
if(jQuery.browser.msie&&parseFloat(jQuery.browser.version)<7){
options.animationSpeed=0;
}
返回此值。每个(函数(){
var carousel=jQuery(此),
元素=carousel.children();
当前项=1;
childWidth=elements.width();
childHeight=elements.height();
如果(元素长度>2){
元素。每个(功能(i){
if(options.itemClass){
jQuery(this.addClass)(options.itemClass);
}
});
elements.filter(':first').addClass(options.currentClass).before(elements.filter(':last'));
var carouselWidth=Math.round(childWidth*carousel.children().length),
carouselMarginLeft='-'+Math.round(childWidth+Math.round(childWidth/2))+'px'
carousel.addClass('hero-carousel-container').css({
'位置':'相对',
“溢出”:“隐藏”,
“左”:50%,
“顶部”:0,
“左边距”:旋转木马左边距,
“身高”:儿童身高,
“宽度”:旋转木马宽度
});
转盘前(“”);
var carouselNav=carousel.prev(“.hero carousel nav”),
时间间隔;
如果(options.timeout>0){
var=false;
如果(选项。暂停){
旋转木马悬停(函数(){
暂停=真;
},函数(){
暂停=错误;
});
}
如果(选项pauseOnNavHover){
carouselNav.hover(函数(){
暂停=真;
},函数(){
暂停=错误;
});
}
函数autoSlide(){
如果(!暂停){
carouselNav.find('.next a').trigger('click');
}
}
timeoutInterval=window.setInterval(自动滑动,选项.timeout);
}
carouselNav.find('a')。data('disabled',false)。单击(函数(e){
e、 预防默认值();
var navItem=jQuery(此),
isPrevious=navItem.parent().hasClass('prev'),
元素=carousel.children();
if(导航项数据('disabled')==false){
选项.onStart(旋转木马、旋转木马、元素.eq(当前项)、选项);
如果(上一个){
animateItem(elements.filter(':last'),'previous');
}否则{
animateItem(elements.filter(':first'),'next');
}
导航项数据(“已禁用”,为真);
setTimeout(函数(){
导航项数据(“已禁用”,错误);
},选项。动画速度+200);
如果(options.timeout>0){
清除间隔(timeoutInterval);
timeoutInterval=window.setInterval(自动滑动,选项.timeout);
}
}
});
函数animateItem(对象、方向){
var carouselPosLeft=parseFloat(carousel.position().left),
carouselprevalginleft=parseFloat(carousel.css('margin-left');
如果(方向==‘上一个’){
object.before(object.clone().addClass('carousel-clone');
转盘预旋(对象);
var marginLeft=Math.round(carouselPrevMarginLeft-childWidth);
变量plusor减号='+=';
}否则{
object.after(object.clone().addClass('carousel-clone');
旋转木马。附加(对象);
var marginLeft=carouselMarginLeft;
var plusor减号='-=';
}
如果(options.css3pieFix){
fixpieclone(jQuery('.carousel clone'));
}
carousel.css({
“左”:转盘左侧,
“宽度”:数学圆(旋转宽度+子宽度),
“左边距”:左边距
}).animate({'left':plusor减号+childWidth},options.animationSpeed,options.easing,function(){
carousel.css({
“左”:50%,
“宽度”:旋转木马宽度,
“左边距”:carouselprevemarginleft
});
jQuery('.carousel clone').remove();
finishCarousel();
});
}
函数fixPieClones(clonedObject){
var itemPieId=clonedObject.attr(“pieId”);
if(itemPieId){
clonedObject.attr(“'u-pieId',itempeid+”'u-cloned');
}
clonedObject.find('*[\u pieId]')。每个(函数(i,项){
var-degenantpieid=$(item.attr)(“pieId”);
$(item).attr(“'u pieId',genderantpieid+”'u cloned');
});
}
函数finishCarousel(){
var elements=carousel.children();
elements.removeClass(options.currentClass).eq(currentItem).addClass(options.currentClass);
选项.onComplete(旋转木马,旋转木马.prev(')。