Best JavaScript code snippet using wpt
jquery.slickscroll.js
Source:jquery.slickscroll.js
1/*2* jQuery Custom Scrollbar Script Oct 20th3* Visit http://www.dynamicdrive.com/ for full source code4*/5/// <reference path="jquery-1.6.2.js" />6(function ($) {7 $.fn.slickscroll = function (options) {8 var scrollcontainer;9 var scrollcontent;10 var scrollbar11 var scrollcontentpos = new Array(0, 0);12 var scrollcontainerpos = new Array(0, 0);13 var mousewheelscrolltop;14 var ap = false;15 var scrollhw = 0;16 //public methods17 this.InValidate = function () {18 scrollhw = (options.verticalscrollbar ? scrollcontent.prop('scrollHeight') : scrollcontent.prop('scrollWidth'));19 $(window).resize();20 }21 this.scrollBy = function (n, speed) {22 if (options.verticalscrollbar) {23 var scrolltop = scrollcontent.scrollTop() + n;24 if (scrolltop < 0) return;25 scrollcontent.animate({ scrollTop: scrolltop + 'px' }, speed);26 scrollbar.css({ "top": scrollcontainerpos.top + scrolltop / (scrollcontent.prop('scrollHeight') / scrollcontent.height()) + "px" });27 }28 else {29 var scrollleft = scrollcontent.scrollLeft() + n;30 if (scrollleft < 0) return;31 scrollcontent.animate({ scrollLeft: scrollleft + 'px' }, speed);32 scrollbar.css({ "left": scrollcontainerpos.left + scrollleft / (scrollcontent.prop('scrollWidth') / scrollcontent.width()) + "px" });33 }34 };35 this.scrollTop = function (speed) {36 if (options.verticalscrollbar) {37 scrollcontent.animate({ scrollTop: '0px' }, speed);38 scrollbar.animate({ top: scrollcontainerpos.top + 'px' }, speed);39 }40 else {41 scrollcontent.animate({ scrollLeft: '0px' }, speed);42 scrollbar.animate({ left: scrollcontainerpos.left + 'px' }, speed);43 }44 };45 this.scrollBottom = function (speed) {46 if (options.verticalscrollbar) {47 scrollcontent.animate({ scrollTop: scrollcontent.prop('scrollHeight') + 'px' }, speed);48 scrollbar.animate({ top: scrollcontainer.height() - scrollbar.height() + scrollcontainerpos.top + 'px' }, speed);49 }50 else {51 scrollcontent.animate({ scrollLeft: scrollcontent.prop('scrollWidth') + 'px' }, speed);52 scrollbar.animate({ left: scrollcontainer.width() - scrollbar.width() + scrollcontainerpos.left + 'px' }, speed);53 }54 };55 this.scrollTo = function (element, speed) {56 var elpos = element.offset();57 if (elpos == null) return;58 if (options.verticalscrollbar) {59 var scrolltop = elpos.top - (scrollcontent.height() / 2) + scrollcontent.scrollTop() - scrollcontainerpos.top - (ap ? scrollcontainer.offset().top : 0);60 scrollcontent.animate({ scrollTop: scrolltop + 'px' }, speed);61 scrollbar.animate({ top: scrollcontainerpos.top + scrolltop / (scrollcontent.prop('scrollHeight') / scrollcontent.height()) + "px" }, speed);62 if (scrollbar.offset().top + scrollbar.height() > scrollcontent.height()) scrollbar.css({ "top": scrollcontainer.height() - scrollbar.height() + scrollcontainerpos.top + "px" });63 }64 else {65 var scrollleft = elpos.left - (scrollcontent.width() / 2) + scrollcontent.scrollLeft() - scrollcontainerpos.left - (ap ? scrollcontainer.offset().left : 0);66 var scrollbarleft = scrollcontainerpos.left + scrollleft / (scrollcontent.prop('scrollWidth') / scrollcontent.width());67 if (scrollbarleft + scrollbar.width() > scrollcontent.width()) scrollbarleft = scrollcontainer.width() - scrollbar.width() + scrollcontainerpos.left;68 scrollcontent.animate({ scrollLeft: scrollleft + 'px' }, speed);69 scrollbar.animate({ left: scrollbarleft + "px" }, speed);70 }71 };72 //end public methods73 //init74 var defaults = {75 verticalscrollbar: false,76 horizontalscrollbar: false,77 container_class_name: 'slickscrollcontainer',78 vertical_scrollbar_class_name: 'slickscroll_vertical_scrollbar',79 horizontal_scrollbar_class_name: 'slickscroll_horizontal_scrollbar',80 min_scrollbar_size: 25,81 mousewheel_scroll_speed: 582 }83 if (options != null) {84 if (options.verticalscrollbar == null) options.verticalscrollbar = defaults.verticalscrollbar;85 if (options.horizontalscrollbar == null) options.horizontalscrollbar = defaults.horizontalscrollbar;86 if (options.container_class_name == null) options.container_class_name = defaults.container_class_name;87 if (options.vertical_scrollbar_class_name == null) options.vertical_scrollbar_class_name = defaults.vertical_scrollbar_class_name;88 if (options.horizontal_scrollbar_class_name == null) options.horizontal_scrollbar_class_name = defaults.horizontal_scrollbar_class_name;89 if (options.min_scrollbar_size == null) options.min_scrollbar_size = defaults.min_scrollbar_size;90 if (options.mousewheel_scroll_speed == null) options.mousewheel_scroll_speed = defaults.mousewheel_scroll_speed;91 }92 else {93 options = defaults;94 }95 $(document).unbind("mouseup");96 //end init97 //slickscroll logic98 return this.each(function () {99 scrollcontent = $(this);100 var scrollcontentparent = scrollcontent.parent();101 scrollhw = (options.verticalscrollbar ? scrollcontent.prop('scrollHeight') : scrollcontent.prop('scrollWidth'));102 scrollcontent.wrap('<div class="' + options.container_class_name + '"></div>'); //append the container103 scrollcontainer = scrollcontent.closest('.' + options.container_class_name); //get a ref to the container104 if (scrollcontent.css("position") == "absolute" || scrollcontent.css("position") == "relative") {105 ap = true;106 scrollcontainer.css({ "position": "absolute", "left": scrollcontent.offset().left + "px", "top": scrollcontent.offset().top + "px" });107 scrollcontent.css({ "position": "static" });108 }109 else if (scrollcontentparent.css("position") == "relative" || scrollcontentparent.css("position") == "absolute") {110 ap = true;111 //scrollcontainer.css({ "position": "absolute", "left": scrollcontentparent.offset().left + "px", "top": scrollcontentparent.offset().top + "px" });112 //scrollcontentparent.css({ "position": "static" });113 }114 if (options.verticalscrollbar) {115 scrollcontainer.prepend('<div class="' + options.vertical_scrollbar_class_name + '"><div></div></div>');116 scrollbar = scrollcontainer.children('.' + options.vertical_scrollbar_class_name);117 }118 else {119 scrollcontainer.prepend('<div class="' + options.horizontal_scrollbar_class_name + '"><div></div></div>');120 scrollbar = scrollcontainer.children('.' + options.horizontal_scrollbar_class_name);121 }122 scrollcontainer.mousedown(function (e) {123 if (options.verticalscrollbar) {124 if (e.pageX < scrollbar.offset().left) return;125 if (ap)126 DoScroll(e, e.pageY - (scrollbar.height() / 2), null);127 else128 DoScroll(e, e.pageY - scrollcontentpos.top - (scrollbar.height() / 2), null);129 }130 else {131 if (e.pageY < scrollbar.offset().top) return;132 if (ap)133 DoScroll(e, null, e.pageX - (scrollbar.width() / 2));134 else135 DoScroll(e, null, e.pageX - scrollcontentpos.left - (scrollbar.width() / 2));136 }137 });138 mousewheelscrolltop = scrollcontent.scrollTop();139 RecalcSize();140 SetIfScrollBarNeedsToBeVisible();141 scrollbar.unbind("mousedown");142 scrollcontent.mousewheel(function (e, delta) {143 if (options.verticalscrollbar) {144 mousewheelscrolltop = scrollbar.offset().top - scrollcontentpos.top;145 if (mousewheelscrolltop < 0) mousewheelscrolltop = 5;146 if (mousewheelscrolltop + scrollbar.height() > scrollcontent.height()) mousewheelscrolltop = scrollcontent.height() - scrollbar.height() - options.mousewheel_scroll_speed;147 mousewheelscrolltop += (delta < 0 ? options.mousewheel_scroll_speed : (options.mousewheel_scroll_speed * -1));148 DoScroll(e, mousewheelscrolltop, null, true);149 }150 else {151 mousewheelscrolltop = scrollbar.offset().left - scrollcontentpos.left;152 if (mousewheelscrolltop < 0) mousewheelscrolltop = 5;153 if (mousewheelscrolltop + scrollbar.width() > scrollcontent.width()) mousewheelscrolltop = scrollcontent.width() - scrollbar.width() - options.mousewheel_scroll_speed;154 mousewheelscrolltop += (delta < 0 ? options.mousewheel_scroll_speed : (options.mousewheel_scroll_speed * -1));155 DoScroll(e, null, mousewheelscrolltop, true);156 }157 return false158 });159 $(document).mouseup(function () {160 scrollbarmouseoffset = 0;161 $(document).unbind("mousemove");162 enableSelection(scrollcontent.get(0));163 enableSelection(document.body);164 });165 $(document).mouseleave(function () {166 $(document).unbind("mousemove");167 enableSelection(scrollcontent.get(0));168 enableSelection(document.body);169 });170 $(document).mousedown(function () {171 enableSelection(scrollcontent.get(0));172 enableSelection(document.body);173 });174 var scrollbarmouseoffset = 0;175 scrollbar.mousedown(function (e) {176 e.stopPropagation()177 $(document).unbind("mousemove");178 if (options.verticalscrollbar)179 scrollbarmouseoffset = (e.pageY - scrollbar.offset().top);180 else181 scrollbarmouseoffset = (e.pageX - scrollbar.offset().left);182 $(document).mousemove(function (e) {183 DoScroll(e, null, null);184 });185 });186 function DoScroll(e, y, x, mw) {187 var scrollbarpos = scrollbar.offset();188 disableSelection(scrollcontent.get(0));189 disableSelection(document.body);190 if (options.verticalscrollbar) {191 if (y == null) y = e.pageY - scrollcontainerpos.top - scrollbarmouseoffset;192 if (ap && !mw) y -= scrollcontentpos.top193 if (y >= 0) {194 if (y + scrollbar.height() <= scrollcontainer.height()) {195 scrollbar.css({ "top": y + scrollcontainerpos.top + "px" });196 scrollcontent.scrollTop(y * (scrollcontent.prop('scrollHeight') / scrollcontent.height()));197 }198 else {199 scrollbar.css({ "top": scrollcontainer.height() - scrollbar.height() + scrollcontainerpos.top + "px" });200 scrollcontent.scrollTop(scrollcontent.prop('scrollHeight'));201 }202 }203 else {204 scrollbar.css({ "top": scrollcontainerpos.top + "px" });205 scrollcontent.scrollTop(0);206 }207 }208 else {209 if (x == null) x = e.pageX - scrollcontainerpos.left - scrollbarmouseoffset;210 if (ap && !mw) x -= scrollcontentpos.left211 if (x >= 0) {212 if (x + scrollbar.width() <= scrollcontainer.width()) {213 scrollbar.css({ "left": x + scrollcontainerpos.left + "px" });214 scrollcontent.scrollLeft(x * (scrollcontent.prop('scrollWidth') / scrollcontent.width()));215 }216 else {217 scrollbar.css({ "left": scrollcontainer.width() - scrollbar.width() + scrollcontainerpos.left + "px" });218 scrollcontent.scrollLeft(scrollcontent.prop('scrollWidth'));219 }220 }221 else {222 scrollbar.css({ "left": scrollcontainerpos.left + "px" });223 scrollcontent.scrollLeft(0);224 }225 }226 }227 $(window).resize(function () {228 RecalcSize();229 SetIfScrollBarNeedsToBeVisible();230 });231 function SetIfScrollBarNeedsToBeVisible() {232 if (options.verticalscrollbar) {233 if (scrollhw <= scrollcontainer.height()) {234 scrollbar.hide();235 scrollcontainer.width(0);236 }237 else {238 scrollbar.show();239 scrollcontainer.width(null);240 }241 }242 else {243 if (scrollhw <= scrollcontainer.width()) {244 scrollbar.hide();245 scrollcontainer.height(0);246 }247 else {248 scrollbar.show();249 scrollcontainer.height(null);250 }251 }252 }253 function RecalcSize() {254 scrollcontentpos = scrollcontent.offset();255 scrollcontainerpos = scrollcontainer.offset();256 if (ap) { scrollcontainerpos.left = 0; scrollcontainerpos.top = 0; }257 if (options.verticalscrollbar) {258 scrollcontainer.css("width", '100%');259 scrollcontent.css("width", ''); //resets the width to whatever is in the .css260 scrollcontainer.width(scrollcontent.width() + scrollbar.width());261 scrollcontent.width(scrollcontainer.width() - scrollbar.width());262 if (ap)263 scrollbar.height((scrollcontent.height() / scrollhw) * scrollcontent.height());264 else265 if (scrollcontent.prop('scrollHeight') != scrollcontent.height()) scrollbar.height((scrollcontent.height() / scrollcontent.prop('scrollHeight')) * scrollcontent.height());266 scrollbar.css({ "left": scrollcontainerpos.left + scrollcontainer.width() - scrollbar.width() + "px" });267 if (scrollbar.height() < options.min_scrollbar_size) scrollbar.height(options.min_scrollbar_size);268 }269 else {270 scrollcontainer.css("width", '100%');271 scrollcontent.css("width", ''); //resets the width to whatever is in the .css272 scrollcontainer.width(scrollcontent.width());273 scrollcontent.width(scrollcontainer.width());274 scrollcontainer.height(scrollcontent.height() + scrollbar.height());275 if (ap)276 scrollbar.width((scrollcontent.width() / scrollhw) * scrollcontent.width());277 else278 if (scrollcontent.prop('scrollWidth') != scrollcontent.width()) scrollbar.width((scrollcontent.width() / scrollcontent.prop('scrollWidth')) * scrollcontent.width());279 scrollbar.css({ "top": scrollcontainer.height() - scrollbar.height() + scrollcontainerpos.top + "px" });280 if (scrollbar.width() < options.min_scrollbar_size) scrollbar.width(options.min_scrollbar_size);281 if (scrollbar.offset().left + scrollbar.width() > scrollcontainerpos.left + scrollcontent.width()) scrollbar.css({ "left": scrollcontainerpos.left + scrollbar.offset().left - (scrollbar.offset().left + scrollbar.width() - scrollcontent.width()) + "px" });282 if (scrollbar.offset().left < scrollcontainerpos.left) scrollbar.css({ "left": scrollcontainerpos.left });283 }284 }285 });286 }287})(jQuery);288//helper functions289function enableSelection(target) {290 if (typeof target.onselectstart != "undefined") //IE route291 target.onselectstart = function () { return true };292 if (typeof target.style.MozUserSelect != "undefined") //Firefox route293 target.style.MozUserSelect = "text";294 if (typeof target.style.KhtmlUserSelect != "undefined") //Firefox/chrome route295 target.style.KhtmlUserSelect = "text";296 target.onmousedown = function () { return true };297}298function disableSelection(target) {299 if (typeof target.onselectstart != "undefined") //IE route300 target.onselectstart = function () { return false };301 if (typeof target.style.MozUserSelect != "undefined") //Firefox route302 target.style.MozUserSelect = "none";303 if (typeof target.style.KhtmlUserSelect != "undefined") //Firefox/chrome route304 target.style.KhtmlUserSelect = "none";305 target.onmousedown = function () { return false };...
scroll-toolbars.js
Source:scroll-toolbars.js
1/*=============================================================2************ Hide/show Toolbar/Navbar on scroll ************3=============================================================*/4app.initPageScrollToolbars = function (pageContainer) {5 pageContainer = $(pageContainer);6 var scrollContent = pageContainer.find('.page-content');7 if (scrollContent.length === 0) return;8 var hideNavbar = (app.params.hideNavbarOnPageScroll || scrollContent.hasClass('hide-navbar-on-scroll') || scrollContent.hasClass('hide-bars-on-scroll')) && !(scrollContent.hasClass('keep-navbar-on-scroll') || scrollContent.hasClass('keep-bars-on-scroll'));9 var hideToolbar = (app.params.hideToolbarOnPageScroll || scrollContent.hasClass('hide-toolbar-on-scroll') || scrollContent.hasClass('hide-bars-on-scroll')) && !(scrollContent.hasClass('keep-toolbar-on-scroll') || scrollContent.hasClass('keep-bars-on-scroll'));10 var hideTabbar = (app.params.hideTabbarOnPageScroll || scrollContent.hasClass('hide-tabbar-on-scroll')) && !(scrollContent.hasClass('keep-tabbar-on-scroll'));11 if (!(hideNavbar || hideToolbar || hideTabbar)) return;12 var viewContainer = scrollContent.parents('.' + app.params.viewClass);13 if (viewContainer.length === 0) return;14 var navbar = viewContainer.find('.navbar'),15 toolbar = viewContainer.find('.toolbar'),16 tabbar;17 if (hideTabbar) {18 tabbar = viewContainer.find('.tabbar');19 if (tabbar.length === 0) tabbar = viewContainer.parents('.' + app.params.viewsClass).find('.tabbar');20 }21 var hasNavbar = navbar.length > 0,22 hasToolbar = toolbar.length > 0,23 hasTabbar = tabbar && tabbar.length > 0;24 var previousScroll, currentScroll;25 previousScroll = currentScroll = scrollContent[0].scrollTop;26 var scrollHeight, offsetHeight, reachEnd, action, navbarHidden, toolbarHidden, tabbarHidden;27 var toolbarHeight = (hasToolbar && hideToolbar) ? toolbar[0].offsetHeight : 0;28 var tabbarHeight = (hasTabbar && hideTabbar) ? tabbar[0].offsetHeight : 0;29 var bottomBarHeight = tabbarHeight || toolbarHeight;30 function handleScroll(e) {31 if (pageContainer.hasClass('page-on-left')) return;32 currentScroll = scrollContent[0].scrollTop;33 scrollHeight = scrollContent[0].scrollHeight;34 offsetHeight = scrollContent[0].offsetHeight;35 reachEnd = currentScroll + offsetHeight >= scrollHeight - bottomBarHeight;36 navbarHidden = navbar.hasClass('navbar-hidden');37 toolbarHidden = toolbar.hasClass('toolbar-hidden');38 tabbarHidden = tabbar && tabbar.hasClass('toolbar-hidden');39 if (reachEnd) {40 if (app.params.showBarsOnPageScrollEnd) {41 action = 'show';42 }43 }44 else if (previousScroll > currentScroll) {45 if (app.params.showBarsOnPageScrollTop || currentScroll <= 44) {46 action = 'show';47 }48 else {49 action = 'hide';50 }51 }52 else {53 if (currentScroll > 44) {54 action = 'hide';55 }56 else {57 action = 'show';58 }59 }60 if (action === 'show') {61 if (hasNavbar && hideNavbar && navbarHidden) {62 app.showNavbar(navbar);63 pageContainer.removeClass('no-navbar-by-scroll');64 navbarHidden = false;65 }66 if (hasToolbar && hideToolbar && toolbarHidden) {67 app.showToolbar(toolbar);68 pageContainer.removeClass('no-toolbar-by-scroll');69 toolbarHidden = false;70 }71 if (hasTabbar && hideTabbar && tabbarHidden) {72 app.showToolbar(tabbar);73 pageContainer.removeClass('no-tabbar-by-scroll');74 tabbarHidden = false;75 }76 }77 else {78 if (hasNavbar && hideNavbar && !navbarHidden) {79 app.hideNavbar(navbar);80 pageContainer.addClass('no-navbar-by-scroll');81 navbarHidden = true;82 }83 if (hasToolbar && hideToolbar && !toolbarHidden) {84 app.hideToolbar(toolbar);85 pageContainer.addClass('no-toolbar-by-scroll');86 toolbarHidden = true;87 }88 if (hasTabbar && hideTabbar && !tabbarHidden) {89 app.hideToolbar(tabbar);90 pageContainer.addClass('no-tabbar-by-scroll');91 tabbarHidden = true;92 }93 }94 previousScroll = currentScroll;95 }96 scrollContent.on('scroll', handleScroll);97 scrollContent[0].f7ScrollToolbarsHandler = handleScroll;98};99app.destroyScrollToolbars = function (pageContainer) {100 pageContainer = $(pageContainer);101 var scrollContent = pageContainer.find('.page-content');102 if (scrollContent.length === 0) return;103 var handler = scrollContent[0].f7ScrollToolbarsHandler;104 if (!handler) return;105 scrollContent.off('scroll', scrollContent[0].f7ScrollToolbarsHandler);...
Using AI Code Generation
1var wptools = require('wptools');2 if (err) {3 console.log(err);4 }5 console.log(data);6});7MIT © [Nishant](
Using AI Code Generation
1var wptbTableSetings = new WptbTableSetings();2wptbTableSetings.scrollContent( 'up', 1, 1 );3### scrollContent( direction, tableId, step )4### scrollContent( direction, tableId, step )5### scrollContent( direction, tableId, step )6### scrollContent( direction, tableId, step )7### scrollContent( direction, tableId, step )
Using AI Code Generation
1var scrollContent = function(scrollTo) {2 var scrollContent = document.getElementById('scroll-content');3 scrollContent.scrollTop = scrollTo;4};5var scrollContent = function(scrollTo) {6 var scrollContent = document.getElementById('scroll-content');7 scrollContent.scrollTop = scrollTo;8};9var scrollContent = function(scrollTo) {10 var scrollContent = document.getElementById('scroll-content');11 scrollContent.scrollTop = scrollTo;12};13var scrollContent = function(scrollTo) {14 var scrollContent = document.getElementById('scroll-content');15 scrollContent.scrollTop = scrollTo;16};17var scrollContent = function(scrollTo) {18 var scrollContent = document.getElementById('scroll-content');19 scrollContent.scrollTop = scrollTo;20};21var scrollContent = function(scrollTo) {22 var scrollContent = document.getElementById('scroll-content');23 scrollContent.scrollTop = scrollTo;24};25var scrollContent = function(scrollTo) {26 var scrollContent = document.getElementById('scroll-content');27 scrollContent.scrollTop = scrollTo;28};29var scrollContent = function(scrollTo) {30 var scrollContent = document.getElementById('scroll-content');31 scrollContent.scrollTop = scrollTo;32};33var scrollContent = function(scrollTo) {34 var scrollContent = document.getElementById('scroll-content');35 scrollContent.scrollTop = scrollTo;36};
Using AI Code Generation
1var id = "post-123";2var scrollFrom = "wptouch-content";3var scrollable = document.getElementById(scrollFrom);4var scrollTo = document.getElementById(id);5var offset = scrollTo.offsetTop;6scrollable.scrollTop = offset;7var scrollFrom = "wptouch-content";8var scrollable = document.getElementById(scrollFrom);9scrollable.scrollTop = 0;10var scrollFrom = "wptouch-content";11var scrollable = document.getElementById(scrollFrom);12var height = scrollable.offsetHeight;13scrollable.scrollTop = height;14var scrollFrom = "wptouch-content";15var scrollable = document.getElementById(scrollFrom);16var height = scrollable.offsetHeight;17var pageHeight = document.body.scrollHeight;18scrollable.scrollTop = pageHeight - height;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!