Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TBLOP V3 List Expander Prototype
- // Grows list height (increasing number of visible links) when hovering
- // after list grows to ~90% of window height, will scroll window to make list full window height
- // huge improvement on the previous version thats been on tblop for years
- tblop.currently = {}
- tblop.currently.hoveringList = false;
- tblop.currently.startingHeight = 256;
- $("div.a_list").hover(
- function () {
- if (!viewingMobile && !tblop.currently.hoveringList) {
- tblop.currently.hoverStartingTime=Date.now();
- tblop.currently.startingHeight = $(this).children("div.list_contents").css('max-height').replace('px', '');
- // this get the total height viewable, not the TOTAL height of the hidden parts
- tblop.currently.totalHeight = $(this).children("div.list_contents").height();
- // each link is 17 pixels high, so multiply the number of links by 17 to get the TOTAL list height.
- tblop.currently.completeHeight = 17 * $(this).children("div.list_contents").children("a").length;
- tblop.currently.heightLeft = tblop.currently.completeHeight - tblop.currently.totalHeight;
- tblop.that = this;
- tblop.listGrowTimer = setInterval(function () {
- var listHeight = $(tblop.that).children("div.list_contents").height();
- // increase max list height by 1 pixel every half second
- // wamt tp grpw the list at a percentage of current height rate.
- tblop.currently.heightLeft = tblop.currently.completeHeight - listHeight;
- var heightToAdd = (tblop.currently.heightLeft / 8.5);
- if (tblop.currently.heightLeft < 10) {
- heightToAdd = 1;
- }
- if (heightToAdd > 8.5) {
- heightToAdd = 8.5;
- }
- if (listHeight > document.body.clientHeight * 0.9) {
- heightToAdd = 0;
- $(tblop.that).children("div.list_contents").css('max-height', (document.body.clientHeight - 96) + 'px');
- listHeight = $(tblop.that).children("div.list_contents").height();
- window.scrollTo(0, $(tblop.that).offset().top);
- clearInterval(tblop.listGrowTimer);
- tblop.listGrowTimer = null;
- }
- if (Date.now()-tblop.currently.hoverStartingTime>1600){
- listHeight += heightToAdd;
- //console.log(tblop.currently.heightLeft);
- $(tblop.that).children("div.list_contents").css('max-height', listHeight + 'px');
- }
- }, 67)
- tblop.currently.hoveringList = true;
- }
- },
- function () {
- if (!viewingMobile) {
- tblop.that = this;
- $(tblop.that).children("div.list_contents").css('max-height', tblop.currently.startingHeight + 'px');
- clearInterval(tblop.listGrowTimer);
- tblop.listGrowTimer = null;
- tblop.currently.hoveringList = false;
- }
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement