I'm a graphic designer and I'm trying to code my new portfolio using some wonderf开发者_Go百科ul jquery scripts. I want to make jcarousel (http://sorgalla.com/projects/jcarousel/) stop on mouseover.
any help is appreciated. thank you!
You can pass an initCallback
function that is called right after initialisation of the carousel.
This function will do the trick: http://groups.google.com/group/jquery-en/browse_thread/thread/f550b94914d10065
var isMouseOver = false;
$(this).mouseover(function(){
isMouseOver = true;
}).mouseout(function(){
isMouseOver = false;
});
//add by koumei-->
function go(to) {
...
...
It is from http://blog.koumei.net/2011/06/01/jcarousel-lite-mouse-hover-event-improvement/
To answer Geert's answer more thoroughly (btw, it works great),
within your settings you add the initCallback function:
initCallback: function(jc, state) {
if (state == 'init') {
/* Pause carousel scrolling when a user mouses overs an item and restart the scrolling when they mouse out.
* Written by cormac at finisco dot com 19/2/2009 based on work by Jeremy Mikola:
* http://groups.google.com/group/jquery-en/browse_thread/thread/f550b94914d10065
*/
jc.startAutoOrig = jc.startAuto;
jc.startAuto = function() {
if (!jc.paused) {
jc.startAutoOrig();
}
}
jc.pause = function() {
jc.paused = true;
jc.stopAuto();
};
jc.play = function() {
jc.paused = false;
jc.startAuto();
};
$('li.jcarousel-item').mouseover(function() {
jc.pause();
});
$('li.jcarousel-item').mouseout(function() {
jc.play();
});
};
jc.play();
},
Below function may be useful for stop animation
itemLoadCallback: {
onBeforeAnimation: function(jc,state){
jc.lock();
}
}
精彩评论