Please assist, i have created dynamic content and i need attach scrollbar to it.
Main goal: when scroller reach to bottom my dynamic content bottom must be synchronized with it. (bottom of color boxes must be inline with the scroller)
Scroller size must be the same and don't change height.
How it will be work: if we have 12 boxes for example, slow speed will be used while scroller reach from top to bottom. if 30 boxes for example, it will be faster and so on...
i think so...
Maybe you provide a better solution.
"create dynamic elements layer" section creates color boxes, please check with different quantity
Thank you
jsFiddle
/* move scrollbar and dynamic elements */
verticalBar.on('dragmove', function (e) {
if (verticalBar.x() != verticalBarBottom.x()) {
verticalBar.x(verticalBarBottom.x())
}
if (verticalBar.y() < verticalBarBottom.y()) {
verticalBar.y(verticalBarBottom.y());
}
if (verticalBar.y() > verticalBarBottom.y() + verticalBarBottom.height() - verticalBar.height()) {
verticalBar.y(verticalBarBottom.y() + verticalBarBottom.height() - verticalBar.height());
}
productsOffset = verticalBar.y() - verticalBarBottom.y();
productsStep = products.getClientRect().height / verticalBarBottom.height();
productsStep = products.getClientRect().height / (verticalBarBottom.y() + verticalBarBottom.height());
newYpos = verticalBarBottom.y() - productPadding;
newYpos -= productsOffset * productsStep;
products.y(newYpos);
products.draw();
})
First, you may need to identify how far your left scrollbar is scrolled. I used progress variable (0 <= progress <= 1):
var progress = (verticalBar.y() - verticalBarBottom.y()) / (verticalBarBottom.height() - verticalBar.height());
Then you may need to identify what is min y and max y that layer may take to fit into you required view:
var minY = verticalBarBottom.y() + verticalBarBottom.height() - products.getClientRect().height;
var maxY = verticalBarBottom.y();
You may need to adjust these variables of your use case.
So real y is just somewhere between minY and maxY adjusted by progress:
var y = minY + (1 - progress) * (maxY - minY);
products.y(y);
Demo: https://jsfiddle.net/ehtro20j/
Related
I have tried to use some the existing solution for iOS keyboard avoiding but none of the existing solutions seems to be working properly with some of my rather complicated views and I am now having to implement my own system. Thus far I have managed to come up with the following which works quite good:
_keyboardDidShow(e) {
const keyboardHeight = e.endCoordinates.height;
const windowHeight = Dimensions.get('window').height;
const keyboardTop = windowHeight - keyboardHeight;
const margin = 10;
const currentlyFocusedField = TextInput.State.currentlyFocusedField();
UIManager.measureInWindow(currentlyFocusedField, (x, y, width, height) => {
const fieldBottom = y + height;
const offset = fieldBottom - keyboardTop + 10;
if (offset > 0) {
this.setState({ offsetY: -1 * offset, offsettingKeyboard: true });
}
});
}
I should mention that these inputs are inside ScrollViews which are themselves in a bunch of other stuff.
The problem is that when the handler is called for a TextInput that has not been scrolled up inside its view, the proper "fieldBottom" position is obtained without adding the height while the height addition is needed for the real position of a field inside a view that has been scrolled.
I cannot decide if this is a bug or if I am missing something. Is there perhaps a way I can check if the input's parent has been scrolled?
I've tried various web searches, but I can't seem to find anything that relates to my problem.
To quickly delineate the problem:
HTML5 Cordova iOS app (7.1 -> 8.1)
uses draggable elements
I only have issues on the iPad, not on the iPhone
The HTML5 app itself works flawlessly in a web-browser
The app itself is a biology app that teaches translation - decoding RNA into a amino acid sequence, i.e. a protein.
For this, the user sees the sequence and drags the correct amino acid onto it. The amino acid is a draggable element and the target div is a droppable. One amino acid at a time a chain is built. Please refer to the screenshot to get an idea (can't embed yet).
http://i.stack.imgur.com/S4UpF.png
In order to fit all screens, I "transform: scale" the app accordingly (fixed size is ~850x550). And to get rid of the associated jQuery bug with draggable (object movement would also change with the scaling factor), I've followed the instructions at http://gungfoo.wordpress.com/2013/02/15/jquery-ui-resizabledraggable-with-transform-scale-set/
// scaling to fit viewport
// sizing the page
var myPage = $('.page');
var pageWidth=myPage.width();
var pageHeight=myPage.height();
// sizing the iFrame
var myFrame = $('.container');
var frameWidth=myFrame.width();
var frameHeight=myFrame.height();
// scaleFactor horizontal
var horizontalScale=pageWidth/frameWidth;
// scaleFactor vertiacal
var verticalScale=pageHeight/frameHeight;
// global zoomScale variable
var zoomScale = 1; // default, required for draggable debug
// if page fits vertically - scale horizontally
if ((frameHeight * horizontalScale) <= pageHeight) {
myFrame.css({
'transform': 'scale('+horizontalScale+')',
'transform-origin': 'top',
});
// adding vertical margin, if possible
if (pageHeight > frameHeight*horizontalScale) {
var heightDifference = pageHeight - frameHeight*horizontalScale;
myPage.css({
'margin-top': heightDifference/2,
'height': pageHeight - heightDifference/2,
});
}
zoomScale = horizontalScale;
// else scale vertically
} else {
myFrame.css({
'transform': 'scale('+verticalScale+')',
'transform-origin': 'top',
});
zoomScale = verticalScale;
}
// draggable + scale transform fixes (http://gungfoo.wordpress.com/2013/02/15/jquery-ui-resizabledraggable-with-transform-scale-set/)
function startFix(event, ui) {
ui.position.left = 0;
ui.position.top = 0;
}
function dragFix(event, ui) {
var changeLeft = ui.position.left - ui.originalPosition.left; // find change in left
var newLeft = ui.originalPosition.left + changeLeft / zoomScale; // adjust new left by our zoomScale
var changeTop = ui.position.top - ui.originalPosition.top; // find change in top
var newTop = ui.originalPosition.top + changeTop / zoomScale; // adjust new top by our zoomScale
ui.position.left = newLeft;
ui.position.top = newTop;
}
I've already got a beta version on iTunes connect and it works great on an iPhone. On iPads, however, the droppable area is oddly small and shifted. That is, the div seems to be properly rendered - it is the box with the dashed border.
Has anyone else encountered a similar bug? I really have no idea how to fix it.
I have managed to solve the problem.
The issue was probably based on the viewport meta tag (0.5 scaling) interacting badly with the transform:scale resizing.
Simply removing all viewport meta arguments have solved the problem.
I'm pretty new to the sdk so forgive me. I want an object to float/transition from the bottom of the screen to the top and keep going until it is out of the device. How do I do that without hard coding the values since all screens have different heights?
First place your object on the bottom of the screen:
object.y = (display.contentHeight + display.screenOriginY * -2) + object.contentHeight * 0.5
//if starting outside of the screen
object.y = (display.contentHeight + display.screenOriginY * -2) - object.contentHeight * 0.5
//if starting at the bottom of the screen
then perform transition.to
transition.to(object, { time = 500, y = 0 - display.screenOriginY })
I wrote it from my memory, so it may not work by copy + paste, but idea stays the same.
object - this is your object you want to transform
display.screenOriginY - this is the distance from the top of the actual screen to the top of the content area (more info here: https://docs.coronalabs.com/api/library/display/screenOriginY.html )
You may also need to read about transitions: http://docs.coronalabs.com/api/library/transition/to.html
widthEssentially, i am creating objects in Flash using actionscript. I currently have a problem where i am resizing the object in actionscript but as the point of reference seems to be the top left hand corner, the object when shrinking seems to also move towards the top left of the screen.
Is there a way to either code the point of origin for an object to the center of the object using code or to have it resize without seemingly moving?
my code for creating and resizing an object is like this (it will grow and shrink but at moment im just tryint to fix this problem before i move on):
var blob1:Loader = new Loader();
blob1.x = 1000;
blob1.y = 450;
blob1.load(new URLRequest("blob1.png"));
addChild(blob1);
blob1.addEventListener(Event.ENTER_FRAME, blobTween);
function blobTween(event:Event)
{
var size = 0;
if (size == 0){
blob1.width += 5;
blob1.height += 5;
}else if (size == 1){
}
Can't you update x and y while you change width and height ?
blob1.x += deltaWidth / 2
blob1.y += deltaHeight / 2
You increment width and height by 5, so deltaWidth = 5 and deltaHeight = 5 .
NOTE: deltaWidth / 2 doesn't divide equally, so you'll have slight shift. I suggest having deltaWidth = 6 and deltaHeight = 6 , or something similar.
GreenSock has a great library for doing just that; TransformManager.
http://www.greensock.com/transformmanageras3/
my solution in the end was a bit strange. I took the shape, divided it into 4 quarters and reattached them in flash by placing the objects in the same place and rotating them (as it rotates from the top left corner, the 4 quarters form a complete shape with each quarter having their top left corner in the centre of the "object"). I then resized them all at once to do it properly.
Whats weird is that the top right and bottom left corners required different math from the other two corners. Which makes no sense whatsoever. 2 corners required width and height to be adjusted. The other two corners required just width to be adjusted. very strange but worked :/
I'm haviing following code
<span class="numbers">
20, 50, 100
</span>
class "numbers" is position absolute element & its using more than one time in a page.
Content inside class"numbers" will be dynamically changing. So I need to apply total width of children to its parent container
I tried this code but not working.
var totalWidth = 0;
$(".numbers").children('a').each(function() {
totalWidth = totalWidth + $(this).width();
$('.numbers').each(function(){$(this).css("width", totalWidth);});
});
But I'm getting totalWidth value 0 only. Can any one help please..........?
Please see http://jsfiddle.net/contactsreejesh/xP3mn/6/
First you need to loop over all the numbers elements. Then within that loop, loop over the children that belong to each individual numbers span
$('.numbers').each(function() {
var totalWidth = 0;
/* "this" in this loop is the current numbers span*/
var $self=$(this)
/* loop over all the children of this element*/
$self.children('a').each(function() {
/* "this" in current loop is an A tag*/
totalWidth += $(this).width();
});
/* now set width*/
$self.width( totalWidth)
})
This statement will affect all the elements with the class in whole page and they would all have the same width
$('.numbers').width(totalWidth);
This works for me as per here.
var w = 0;
$('.numbers').find('a').each(function(){
w += $(this).width();
});
Check this fiddle http://jsfiddle.net/FGmYU/
the change is this:
totalWidth += $(this).width();
The input shows you that the calculated width is 56.