Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Only load iframes once they're visible
Browse files Browse the repository at this point in the history
This fixes an annoying UX issue where clicking a jump link in the sidebar wouldn't take you to the correct location since the act of scrolling would load all previous component iframes.

Now, iframes are only loaded if they're visible in the viewport (for at least 100ms, the default setting of in-view.js)
  • Loading branch information
mpetrovich committed Jul 4, 2018
1 parent 775cc7f commit eba7fee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@

// Lazy-loaded iframes
lazyframe('[lazyframe]', {
lazyload: true,
debounce: 50,
lazyload: false,
onAppend: function(iframe) {
// delay the iFrameResize call to allow the iframeResizer.contentWindow.min.js script
// to load in the iframe first
Expand All @@ -76,6 +75,11 @@
},
});

// Only loads iframes once they're visible
inView('[lazyframe]').on('enter', function(elem) {
$(elem).click();
});

// Prefixes all section links with the element name
$('.i-library').each(function() {
var $library = $(this);
Expand Down
6 changes: 6 additions & 0 deletions src/assets/js/vendor/in-view.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/templates/index.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<script src="_stylemark/js/vendor/lazyframe.min.js"></script>
<script src="_stylemark/js/vendor/highlight.min.js"></script>
<script src="_stylemark/js/vendor/clipboard.min.js"></script>
<script src="_stylemark/js/vendor/in-view.min.js"></script>
<script src="_stylemark/js/app.js"></script>

{{#each options.theme.js}}
Expand Down

0 comments on commit eba7fee

Please sign in to comment.