sticky button position

Hi,

I have a mobile form that expands and displays a considerable amount of fields.
What I would like is to display the submit button in a fixed position at the bottom of the viewport until the user scrolls down to where the button 'should be' located and then it rejoins its position in the page if you were to scroll past it.

Is this easy to do?

Thanks
Al4ddin2Asked:
Who is Participating?
 
COBOLdinosaurConnect With a Mentor Commented:
You can fix the the position of an element relative to the viewport with:

.yourbutton {position;:fixed; left:10px; bottom:0px;}

To get it out of the fixed positioning, you will need to detect when the scroll goes far enough to show thw bottom of the form, and then change the button to absolute positioning within the form.

The tricky part id going to be determining the actual point where the scroll position actually reaches the trigger point in anything responsive or dynamic where the dimension of the page change based on user actions.

Cd&
0
 
Al4ddin2Author Commented:
Hi,

I think I understand what is needed, when the button is beneath the viewport then apply a class to give it a fixed position, then when it's actual position in the DOM comes back into the viewport the class is removed.
The point I am struggling with is how to determine, a) how to addClass at the correct time b) when to removeClass

Thanks
0
 
COBOLdinosaurConnect With a Mentor Commented:
There is an article by Ben Olson on his blog that explains how to create the hooks, detect the position and respond using jquery:

http://www.benknowscode.com/2013/07/detect-dom-element-scrolled-with-jquery.html

Rather than try to modify the style values, you will probably find swapping styles cleaner, and it is more efficient as well.

Cd&
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
Al4ddin2Author Commented:
Thanks that looks great, so does http://www.appelsiini.net/projects/viewport even more so perhaps as I can target if it is above/below etc too.
however, for my purpose neither are working as I want to add a class to a button to say that if its location in the page is below the fold then give it a fixed position at the bottom of the screen until its actual position comes back into the viewport and then remove the class so it resumes its natural position.
Can you get this to work in my situation? as when I give it a fixed position it then appears in the viewport, passes the check and the class is removed.

Aaaargh! :-)

Thanks
0
 
COBOLdinosaurCommented:
Without seeing how the page is reacting to the events it is impossible to visualize what is happening.  You need to post the link so I can see what it is doing.

Cd&
0
 
Al4ddin2Author Commented:
Unfortunately I don't have a link to post as it's all in sandbox at the moment. But using the links above are you able to position a div (that is someway down a long page, below the fold) fixed to the bottom of the screen until it's actual position comes into view?

I have it adding and removing classes at the appropriate times until I add a fixed position to the class I am appending.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.