Note that there are some explanatory texts on larger screens.

plurals
  1. POMove image with touchmove event on iPad
    primarykey
    data
    text
    <p>I have a website that has a fixed background image which I am trying to adapt for the iPhone and iPad as the image does not stay static. I have tried various wrappers with no luck; either I can't scroll one way, or the site doesn't scroll properly (because of the use of dynamic ajax). So I started looking if there was a way to move the image background with the scrolling of the page and I used the following:</p> <pre><code>$(document).bind('touchmove',function(e){ $('.background_image').css({top: $(document).scrollTop()}); $('.background_image img').css({top: $(document).scrollTop()}); console.log($('.background_image img').css('top')); }); $(document).bind('scroll', function() { $('.background_image').css({top: $(document).scrollTop()}); $('.background_image img').css({top: $(document).scrollTop()}); }); </code></pre> <p>This seems to work for the first 'touch', but the background does not then continually move. When I stop moving the 'scroll' bind kicks in and moves the image in to the correct place. Is this a possible feat or am I trying to achieve the impossible here? Logging the output shows that the css is indeed being changed, but the screen is not being updated with it.</p> <p>UPDATE</p> <p>I don't know if it helps, but here is the HTML/CSS I'm using currently:</p> <pre><code>&lt;div class="background_image"&gt; &lt;img src="image.jpg" /&gt; &lt;/div&gt; .background_image { position: fixed; left: 0px; top: 0px; overflow: hidden; z-index: -1; } .background_image img { position: fixed; overflow: hidden; top: 0px; left: 0px; background: white; } </code></pre> <p>Have also changed my code to something slightly easier.</p> <p>Cheers,</p> <p>Dan</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload