Run jQuery function on resize if condition is met -
i trying run script show message when hovering on logo. want run on screen sizes larger 768.e.g not mobiles. div appear , show random message list.
on resize check if content container equal or larger 692, , if add class hoverinfo body. want run script if class exists, yet script still runs regardless.
currently run script on doc.ready, run script check width on window resize , doc.ready.
any appreciated!
$(function(){ function checkwidth() { if ($('#content-wrap').width() == 692) { $('body').addclass('hoverinfo'); } else { $('body').removeclass('hoverinfo'); } } checkwidth(); $(window).resize(function () { settimeout(checkwidth, 200); }); function showtext(){ $randomtext = $(".page #messages"); $(".hoverinfo #logo").hover( function () { $randomtext.show(); }, function () { $randomtext.hide(); } ); } showtext(); });
i don't think hover works live event in jquery. set , stay rest of page load.
try;
$(".no-touch .page.hoverinfo #logo").on("mouseenter", function(){ $randomtext.show(); var aux=hovertext($text); $(".page #messages li:eq("+aux+")").show(); $("#logo").css('opacity','1'); }); $(".no-touch .page.hoverinfo #logo").on("mouseleave", function(){ $randomtext.hide(); $text.hide(); $("#logo").css('opacity','1'); });
also, think have typo;
if ($('#content-wrap').width() == 692) {
should be;
if ($('#content-wrap').width() >= 692) {
Comments
Post a Comment