我一直在試圖用'mouseenter'事件來對現有點擊功能添加一個鼠標滾動功能,並且似乎沒有找到實現預期的正確公式影響。jQuery:將鼠標事件添加到自定義點擊功能
原始代碼:
$('.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;
}
只需改變一下來「的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。
我會感謝您的幫助,謝謝。
我只寫了我修改過的部分,並更新了代碼。正如你所看到的,點擊事件不再存在,我根本不知道如何將懸停/ uiswipe結合到現有點擊之上,而不是替換它。 – willio
您是否特別想知道如何使用懸停並點擊,以便觸摸用戶仍然能夠看到觸發的兩個事件? – Scrimothy
是的,我還希望桌面用戶除了點擊之外還能夠通過鼠標懸停觸發功能。有小費嗎? – willio