User Tools

Site Tools


script_infinite_scrolling

====== About the script ====== * Purpose : This script will make your container loop through pages on scrolling in both horizontal and vertical direction. * Author : [[https://plus.google.com/+Lukas Morawietz|LM13]] * Current Version : 1.5 * Link : https://plus.google.com/115366157037831519359/posts/6fongJozQHs **Note: This script is useless since LLX Version 10.6b1, because this is now a native feature (called seamless)** ====== Changelog ====== * Version 1.5 (5/4/2014): bugfix * Version 1.4 (1/4/2014): added configuration and bugfix * Version 1.3 (31/3/2014): initial release in wiki ====== How to use the script ====== * set the script in the Positionchanged-event of your container * enable infinite scroll * disable fit desktop to items * set up your configuration at the beginning of the script * recommended: enable snap to pages ====== Issues and hints ====== * don't use with any other script using containers' tag! * on one scrolling point it may flicker. Workaround: detach all items on most right/bottom pages from Grid. * using dual position and switching layout may break it. I recommend to use it with only one orientation. * use with caution! There are only seldom bugs, but they may fully break your layout. //please report all bugs in the g+ community// ====== Script code ====== <sxh javascript;>//config var horizontalScrolling=true; var verticalScrolling=true; //endconfig var d=LL.getEvent().getContainer(); if(d.getId()==-1)d=LL.getCurrentDesktop(); if(d.getPositionScale()!=1)return; var data=JSON.parse(d.getTag()||"null"); if (data==null) { data=new Object(); data.stateX=0; data.stateY=0; data.running=false; } if(data.running==true)return; data.running=true; d.setTag(JSON.stringify(data)); var dwidth=d.getWidth(); var dheight=d.getHeight(); var cwidth=d.getCellWidth(); var cheight=d.getCellHeight(); var posX=d.getPositionX(); var posY=d.getPositionY(); var box=d.getBoundingBox(); var minX=box.getLeft(); var maxX=box.getRight(); var minY=box.getTop(); var maxY=box.getBottom(); var fullwidth=maxX-minX; var fullheight=maxY-minY; var items=d.getItems(); var setLeft=function() { data.stateX=1; for(x=0;x<items.getLength();x++) { var item=items.getAt(x); if(item.getPositionX()>=maxX-dwidth) { if(item.getProperties().getBoolean("i.onGrid")) { var cell=item.getCell(); item.setCell(Math.round(cell.getLeft()-fullwidth/cwidth), Math.round(cell.getTop()), Math.round(cell.getRight() -fullwidth/cwidth), Math.round(cell.getBottom())); } else { item.setPosition(item.getPositionX()-fullwidth,item.getPositionY()); } } } } var setRight=function() { data.stateX=0; for(x=0;x<items.getLength();x++) { var item=items.getAt(x); if(item.getPositionX()<minX+dwidth) { if(item.getProperties().getBoolean("i.onGrid")) { var cell=item.getCell(); item.setCell( Math.round(cell.getLeft()+fullwidth/cwidth), Math.round(cell.getTop()), Math.round(cell.getRight() +fullwidth/cwidth), Math.round(cell.getBottom())); } else { item.setPosition(item.getPositionX()+fullwidth,item.getPositionY()); } } } } var setTop=function() { data.stateY=1; for(x=0;x<items.getLength();x++) { var item=items.getAt(x); if(item.getPositionY()>=maxY-dheight) { if(item.getProperties().getBoolean("i.onGrid")) { var cell=item.getCell(); item.setCell(Math.round(cell.getLeft()), Math.round(cell.getTop()-fullheight/cheight), Math.round(cell.getRight()), Math.round(cell.getBottom()-fullheight/cheight)); } else { item.setPosition(item.getPositionX(),item.getPositionY()-fullheight); } } } } var setBottom=function() { data.stateY=0; for(x=0;x<items.getLength();x++) { var item=items.getAt(x); if(item.getPositionY()<minY+dheight) { if(item.getProperties().getBoolean("i.onGrid")) { var cell=item.getCell(); item.setCell( Math.round(cell.getLeft()), Math.round(cell.getTop()+fullheight/cheight), Math.round(cell.getRight()), Math.round(cell.getBottom()+fullheight/cheight)); } else { item.setPosition(item.getPositionX(),item.getPositionY()+fullheight); } } } } if(fullwidth>dwidth && horizontalScrolling) { if(data.stateX==1) { if(posX<=minX || posX>=minX+dwidth) { if(posX<=minX) d.setPosition(maxX,posY,1,false); setRight(); } } else { if(posX<minX) setLeft(); if(posX>maxX-dwidth) { d.setPosition(minX-dwidth,posY,1,false); setLeft(); } } } else { if(posX<minX) d.setPosition(minX,posY,1,false); if(posX>maxX-dwidth) d.setPosition(maxX-dwidth,posY,1,false); } posX=d.getPositionX(); if(fullheight>dheight && verticalScrolling) { if(data.stateY==1) { if(posY<=minY || posY>=minY+dheight) { if(posY<=minY) d.setPosition(posX,maxY,1,false); setBottom(); } } else { if(posY<minY) setTop(); if(posY>maxY-dheight) { d.setPosition(posX,minY-dheight,1,false); setTop(); } } } else { if(posY<minY) d.setPosition(posX,minY,1,false); if(posY>maxY-dheight) d.setPosition(posX,maxY-dheight,1,false); } var done=function() { data.running=false; d.setTag(JSON.stringify(data)); } setTimeout(done,0); </sxh>

script_infinite_scrolling.txt · Last modified: 2015/08/31 21:16 by lm13