我一直在尝试将 'mouseenter' 事件添加到现有单击功能上的附加鼠标悬停功能,但似乎没有找到正确的公式来达到预期的效果。
原始代码:
$('.navhandle, .navcontainer, #tray-button, .page-template-template-home-php .lines, .single-portfolio .lines').hover(
function(){ $('#supersized img').addClass('resize'); //add class for css3 transitions
$thisid = $(this).attr("id");
$thisclass = $(this).attr("class");
$navnow = $('.navhandle').css('left');
if ($navnow == navhandleinit) {
if (($thisid == 'tray-button')) {
$('#thumb-tray').stop().animate({bottom : 0}, 300);
}
$('#prevslide').stop().animate({left: 25 }, 500, 'easeOutCubic');
$('.navcontainer').stop().animate({ left: -210 }, 500, 'easeOutCubic');
$('.navhandle').stop().animate({ left: -10 }, 500, 'easeOutCubic');
$('.mainbody').stop().animate({marginLeft: 10}, 500, 'easeOutCubic', function(){ $('#supersized img').removeClass('resize'); }); //remove css3 transition class after completion
$('.videowrapper').animate({width: '120%', paddingLeft:0}, 500, 'easeOutCubic');
$('.nav').fadeOut(500, 'easeOutCubic');
$('.navhandle').toggleClass("rightarrow");
},function(){ $('#prevslide').stop().animate({left: 245}, 500, 'easeOutCubic');
$('.navcontainer').stop().animate({ left: 0 }, 500, 'easeOutCubic');
$('.navhandle').stop().animate({ left: navhandleinit}, 500, 'easeOutCubic');
$('.mainbody').stop().animate({marginLeft: 220}, 500, 'easeOutCubic', function(){ $('#supersized img').removeClass('resize'); }); //remove css3 transition class after completion
$('#thumb-tray').stop().animate({bottom : -$('#thumb-tray').height()}, 300);
$('.videowrapper').animate({paddingLeft: 220, width: '100%'}, 500, 'easeOutCubic');
$('.nav').fadeIn(500, 'easeOutCubic');
$('.navhandle').toggleClass("rightarrow");
$navnow = navhandleinit;
}
只需将“click”更改为“mouseenter”即可触发效果,但不能将其隔离到特定元素。
失败的尝试:
jQuery(function($) {
var navhandleinit = $('.navhandle').css('left');
var navwidth = $('.navcontainer').width() + 30;
var mainmargin = $('.mainbody').css('margin-left');
var $navnow = $('.navhandle').css('left');
var navtray = $('#thumb-tray').css('left');
$('.navhandle, .navcontainer').mouseenter(function() {
$('#supersized img').addClass('resize');
$thisid = $(this).attr("id");
$thisclass = $(this).attr("class");
$navnow = $('.navhandle').css('left');
if ($navnow == navhandleinit) {
if (($thisid == 'tray-button')) {
$('#thumb-tray').stop().animate({bottom : 0}, 300);
}
$('#prevslide').stop().animate({left: 25 }, 500, 'easeOutCubic');
$('.navcontainer').stop().animate({ left: -210 }, 500, 'easeOutCubic');
$('.navhandle').stop().animate({ left: -10 }, 500, 'easeOutCubic');
$('.mainbody').stop().animate({marginLeft: 10}, 500, 'easeOutCubic', function(){ $('#supersized img').removeClass('resize'); }); //remove css3 transition class after completion
$('.videowrapper').animate({width: '120%', paddingLeft:0}, 500, 'easeOutCubic');
$('.nav').fadeOut(500, 'easeOutCubic');
$('.navhandle').toggleClass("rightarrow");
} else {
$('#prevslide').stop().animate({left: 245}, 500, 'easeOutCubic');
$('.navcontainer').stop().animate({ left: 0 }, 500, 'easeOutCubic');
$('.navhandle').stop().animate({ left: navhandleinit}, 500, 'easeOutCubic');
$('.mainbody').stop().animate({marginLeft: 220}, 500, 'easeOutCubic', function(){ $('#supersized img').removeClass('resize'); }); //remove css3 transition class after completion
$('#thumb-tray').stop().animate({bottom : -$('#thumb-tray').height()}, 300);
$('.videowrapper').animate({paddingLeft: 220, width: '100%'}, 500, 'easeOutCubic');
$('.nav').fadeIn(500, 'easeOutCubic');
$('.navhandle').toggleClass("rightarrow");
$navnow = navhandleinit;
}
});
});
如何有效地添加 mouseenter 事件,以及可选的平板电脑滑动事件,同时保持原始的单击事件功能?
可在http://stage.daylight.pro获得实时页面。
我会很感激你的帮助,谢谢。