Jquery循环选项卡,尝试添加悬停功能

时间:2013-01-08 01:19:33

标签: jquery tabs hover cycle

有人可以帮忙吗?

实施例: http://goo.gl/6Wpn7

* 我试图在这里添加一个悬停功能,而不是单击该项来触发锚点/又转到相关幻灯片 - 是否像看起来那么复杂? *

代码:

JQUERY

$slideshow = {
context: false,
tabs: false,
timeout: 2000,      // time before next slide appears (in ms)
slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
fx: 'fade',   // the slide effect to use

init: function() {
// set the context to help speed up selectors/improve performance
this.context = $('#slideshow');

// set tabs to current hard coded navigation items
this.tabs = $('ul.slides-nav li', this.context);

// remove hard coded navigation items from DOM 
// because they aren't hooked up to jQuery cycle
this.tabs.remove();

// prepare slideshow and jQuery cycle tabs
this.prepareSlideshow();
},

prepareSlideshow: function() {
// initialise the jquery cycle plugin -
// for information on the options set below go to: 
// http://malsup.com/jquery/cycle/options.html
$('div.slides > ul', $slideshow.context).cycle({
fx: $slideshow.fx,
timeout: $slideshow.timeout,
speed: $slideshow.slideSpeed,
fastOnEvent: $slideshow.tabSpeed,
pager: $('ul.slides-nav', $slideshow.context),
pagerAnchorBuilder: $slideshow.prepareTabs,
before: $slideshow.activateTab,
pauseOnPagerHover: true,
pause: true
});    


$(".slides-nav li a").hover(
function(event) {
$(this).removeClass('on');


},
function (event) {
// The mouse has left the element, can reference the element via 'this'
}
);        
},

prepareTabs: function(i, slide) {
// return markup from hardcoded tabs for use as jQuery cycle tabs
// (attaches necessary jQuery cycle events to tabs)
return $slideshow.tabs.eq(i);
},

activateTab: function(currentSlide, nextSlide) {
// get the active tab
var activeTab = $('a [href="#' + nextSlide.id + '"]', $slideshow.context);

// if there is an active tab
if(activeTab.length) {
// remove active styling from all other tabs
$slideshow.tabs.removeClass('on');

// add active styling to active button
activeTab.parent().addClass('on');
}            
}            
};


$(function() {
// add a 'js' class to the body
$('body').addClass('js');

// initialise the slideshow when the DOM is ready
$slideshow.init();
});  

2 个答案:

答案 0 :(得分:1)

您可以使用pagerEvent: 'mouseover'选项

答案 1 :(得分:0)

你可以做一个简单的工作,比如。

$(".slides-nav li a").hover(function(){
    $(this).click();
}, function(){
    //do nothing
});

使用该悬停并单击将同时工作。