I want to position my loading animation on the same line, inside my input box, to the right.
I tried :
<span>
<input id="searchbox" placeholder="Enter Catalog # " type="text" />
<img style="float:right;" id='loading' width="100px" src="http://rpg.drivethrustuff.com/shared_images/ajax-loader.gif"/>
</span>
I get :
I couldn't get it to show inside my input box. :(
My solution: add a class to the input element that defines a background image, then modify its position with background-position-x and background-position-y
you can also use keywoords for postioning
or combine them
then, you can just add or remove this class to show/hide the animation
Try the following:
Set
position: relative;
on the imagetop
CSS attribute to shift the animation upward to the point where it is directly on top of the input field.You can also do it as a background image in CSS. Just create a CSS class and apply at the time of loading the data. After Ajax call is completed remove the "loading" CSS class from the text input box.
You can view it here: http://jsfiddle.net/tejsoft/7pzgtevv/4/
Try fiddling around with absolutely positioning the element.
fiddle
https://jsfiddle.net/kmbxawdd/2/
Furthermore, you can set the containing elements position to relative, meaning you can style directly to these dimensions rather than the documents.
just include
<img>
element inside<input>
element.then you can use js to show and hide this image using id attribute.I agree with @Sam in that it could be the background of the element, and all you'd have to toggle would be a class. If you set it up like:
And then you can toggle the class as you're making your ajax call like:
That, in my opinion, would be the simplest and most effective way of doing it. If you want to look further, here's a fiddle