JQuery visiblechange event
How do I make an jquery visiblechange event?
Limited to the cases when the elements are not moved in the DOM.. What is a jquery visiblechange event? How do you make a jquery visiblechange event? This script and codes were developed by Andrey Shchekin on 15 November 2022, Tuesday.
JQuery visiblechange event - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>jQuery visiblechange event</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="container"> <div id="parent"> <div id="child"> </div> </div>
</div>
<div><input type="checkbox" id="show-parent" />Show parent</div>
<div><input type="checkbox" id="show-child" />Show child</div>
<div><input type="checkbox" id="mutation-observer" />MutationObserver</div>
<div>Visible: <output id="visible">false</output></div> <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js'></script> <script src="js/index.js"></script>
</body>
</html>
JQuery visiblechange event - Script Codes CSS Codes
@import url(https://fonts.googleapis.com/css?family=Open+Sans);
body { padding: 20px; font-family: 'Open Sans', 'Segoe UI', sans-serif;
}
input[type=checkbox] { margin-right: 5px;
}
.container { width: 100px; height: 100px; float: left; margin-right: 10px; background: #d1e5fa;
}
#parent { display: none; background: #a2cbf6; margin-top: 10px; margin-bottom: 10px; width: 100px; height: 80px;
}
#child { display: none; width: 80px; height: 80px; margin-left: 10px; margin-right: 10px; background: #74b1f1;
}
JQuery visiblechange event - Script Codes JS Codes
(function($) { $.event.special.visiblechange = (function() { var visibleDataKey = '__visiblechange__.data'; function setup() { var $element = $(this); var visible = $element.is(':visible'); var unobserve = window.MutationObserver ? observeWithMutationObserver($element) : observeWithSetInterval($element); $element.data(visibleDataKey, { unobserve: unobserve, oldVisible: visible }); } function observeWithMutationObserver($element) { var observer = new MutationObserver(function(events) { checkVisible($element); }); $element.parents().addBack().each(function() { observer.observe(this, { attributes: true, attributeFilter: ['style'] }); }); return function() { return observer.disconnect(); }; } function observeWithSetInterval($element) { var timer = window.setInterval(function() { checkVisible($element); }, 500); return function() { window.resetInterval(timer); }; } function checkVisible($element) { var data = $element.data(visibleDataKey); var newVisible = $element.is(':visible'); if (newVisible === data.oldVisible) return; console.log('visiblechange!'); data.oldVisible = newVisible; var event = $.Event("visiblechange"); event.visible = newVisible; $element.trigger(event); } function teardown() { var $element = $(this); var data = $element.data(visibleDataKey); data.unobserve(); $element.data(visibleDataKey, null); } return { noBubble: true, setup: setup, teardown: teardown }; })(); $.fn.visiblechange = function(callback) { this.on('visiblechange', callback); };
})(jQuery);
$('#show-parent').change(function() { $('#parent').toggle(this.checked);
});
$('#show-child').change(function() { $('#child').toggle(this.checked);
});
var $child = $('#child');
function subscribe() { $child.visiblechange(function(e) { $('#visible').val(e.visible); });
}
subscribe();
window._savedMutationObserver = window.MutationObserver;
$('#mutation-observer').each(function() { this.checked = !!window.MutationObserver; this.disabled = !window.MutationObserver;
}).change(function() { window.MutationObserver = this.checked ? window._savedMutationObserver : null; $('#visible').val(''); $child.off('visiblechange'); subscribe();
});
Developer | Andrey Shchekin |
Username | ashmind |
Uploaded | November 15, 2022 |
Rating | 3 |
Size | 3,129 Kb |
Views | 22,264 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Hexagons | 4,360 Kb |
A Pen by Andrey Shchekin | 2,336 Kb |
Simple CORS test UI | 4,033 Kb |
Diamond-Square Terrain II | 2,928 Kb |
Labyrinth 1 | 2,777 Kb |
Code Loader | 2,153 Kb |
Text Effect 1 | 3,585 Kb |
Click to Shutdown | 2,487 Kb |
Wait what | 3,977 Kb |
TV Fall | 3,293 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
LBCA - Mail canvas | Emnbdx | 3,856 Kb |
IPhone5S SVG Space Grey | Onlinechris | 75,035 Kb |
This in constructor context | _shree33 | 1,718 Kb |
Cofee and sugar | Tripack | 2,094 Kb |
Automatic scroll | Skeurentjes | 4,042 Kb |
CSS Gem Badge | Orchard | 3,335 Kb |
700 Synapses Per Second | Silentkrange | 2,138 Kb |
A Pen by Stan Williams | Stanssongs | 6,706 Kb |
Pomodoro Clock | Osycon | 3,705 Kb |
Pure CSS Torch Light | Juliendargelos | 2,727 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!