Si la largeur de la fenêtre sur la charge de la page ET le redimensionnement est inférieure à 768px, je ne veux pas déclencher la fonction showCover()
. Avec le code ci-dessous, même lorsque la fenêtre est inférieure à 768px, elle est toujours en train de se déclencher.
function ipsThemeViewer() { jQuery(window).resize(function() { if ( jQuery(window).width() < 768 ) return false; showCover(); }).resize(); } function showCover() { jQuery('#ipsThemeViewerScreen').hover(function () { var t = jQuery(this); jQuery('.cover').stop().fadeIn('fast'); }, function () { var t = jQuery(this); jQuery('.cover').stop().fadeOut('fast'); }); }
J'irais en revanche:
jQuery(function($) { // DOM READY AND SECURE $ ALIAS var winIsSmall; function testWinSize(){ winIsSmall= $(window).width() < 768; // BOOLEAN } $(window).on("load resize", testWinSize); $('#ipsThemeViewerScreen').hover(function () { if(winIsSmall){ // need something here? }else{ $('.cover').stop().fadeToggle('fast'); } }); });