I am developing a mobile app. I use JavaScript for the code and some jQuery mobile (1.4.5). My problem is that when I scroll, my images follow the scroll. I don't have this problem in the web version, but on my phone the images are not fixed. I would like my images to be fixed in the specific positions I want while I am scrolling on any device. Let me explain briefly my code:
- When I open my app, some images appear in their places. For this, I simply use:
<img src="js/image.jpg" style="position: absolute; top:105px; left:10px;" width="110" height="85">
which works fine, this image stays in place even in the mobile app.
- then later, others pictures have to appear. For this, I use this function:
function im2(a,b,c,d){var x = document.createElement("IMG");
x.setAttribute("src", a);
x.setAttribute("style",b);
x.setAttribute("width", c);x.setAttribute("height",d );
document.body.appendChild(x);
}
Then to call the image:
<im2("js/image2.jpg","position: fixed; top:210px ; left:165px","280","35")>
Then when I scroll, this image is not fixed anymore on mobile (works fine in web ) ... :-(
- So, I tried this CSS to stick the image, in order to disable it from moving
<style>
img.sticky {
position: -webkit-sticky;
position: sticky;
}
</style>
In the Javascript, I use the same function im2 : im2(w, etc){ x.setAttribute("class", w); etc}
Then, I call the function like this:
im2("sticky","js/image2.jpg","position: fixed; top:210px ; left:165px","280","35")
and .... nothing stick.
I presume this is because of the jqm layer that gives this unexpected result. So, what should I do /write?