Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2012, 03:32 AM   PM User | #1
eydg
New Coder

 
Join Date: Sep 2012
Posts: 70
Thanks: 1
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
make screen unscrollable

I want to make an app in html and css and phonegap it.

For a more realistic standalone behavior i need to disable elastic dragging capability (vertical scrolling) at lower resolutions.

How to achieve that?

I found this, but it does not seem to work:

Code:
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width;" />
        <script type="text/javascript">
            window.addEventListener('load', function() {
                document.body.addEventListener('touchmove', function(e) {
                    e.preventDefault();
                }, false);
            }, false);
        </script>
        <title>Mobile Web App</title>
    </head>
    <body>
        <div id="app">
            <!-- Add your content here -->
        </div>
    </body>
</html>

Neither does this:
Code:
<body {overflow:hidden} >
eydg is offline   Reply With Quote
Old 11-13-2012, 08:13 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,587
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Try html, body {overflow: hidden;} ?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 11-13-2012, 08:35 AM   PM User | #3
Labrar
New Coder

 
Join Date: Jun 2008
Posts: 61
Thanks: 0
Thanked 12 Times in 12 Posts
Labrar is an unknown quantity at this point
First of all
PHP Code:
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"
should work for the right resolution. (By the way. For a web app you have to use 640 x 920 for Iphones)
It doesn't matter if you convert it with phonegap. Still's just a web app but into the I Store (if apple take it)

Seccond

PHP Code:
document.ontouchstart=document.onmousedown=preventer;
function 
preventer(e){    
                if(!
e){e=window.event;}
        
e.preventDefault();
                
    } 
EDIT:
To make it more realistic use this also
PHP Code:
window.scrollTo(0,0,0); 
So your url bar will dissapear
Labrar is offline   Reply With Quote
Old 11-14-2012, 04:02 AM   PM User | #4
eydg
New Coder

 
Join Date: Sep 2012
Posts: 70
Thanks: 1
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
Thank you very much for clarifying this simple fact that some lines of the code are not js, I made an assumption that whatever is not apparent html, it must be js


I have tried the following css
Code:
<style> html, body {overflow: hidden;} 
</style>
and it does remove the vertical scrolling bar from the browser.


I have done the adjustments to the code and run an android simulator, and there seems to be no change. Here's what I typed in:

Code:
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">  





<?php
document.ontouchstart=document.onmousedown=preventer;
function preventer(e){    
                if(!e){e=window.event;}
        e.preventDefault();
}  

window.scrollTo(0,0,0);  
?>
eydg is offline   Reply With Quote
Old 11-14-2012, 08:10 AM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
This is not php - it is Javascript. Labrar used the wrong tags.

Code:
<script type = "text/javascript">
document.ontouchstart=document.onmousedown=preventer;
function preventer(e){    
if(!e){e=window.event;}
e.preventDefault();
}  
</script>
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 11-14-2012, 08:27 AM   PM User | #6
Labrar
New Coder

 
Join Date: Jun 2008
Posts: 61
Thanks: 0
Thanked 12 Times in 12 Posts
Labrar is an unknown quantity at this point
Thats true
Sorry
Labrar is offline   Reply With Quote
Old 11-14-2012, 05:03 PM   PM User | #7
eydg
New Coder

 
Join Date: Sep 2012
Posts: 70
Thanks: 1
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
It does work! Many thanks.

In case someone needs it summed up, here it is:

Code:
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">  
<script type = "text/javascript">
document.ontouchstart=document.onmousedown=preventer;
function preventer(e){    
if(!e){e=window.event;}
e.preventDefault();
}  
</script>

</head>

<body>


<style> html, body {overflow: hidden; } 
</style>
eydg is offline   Reply With Quote
Old 11-14-2012, 06:25 PM   PM User | #8
eydg
New Coder

 
Join Date: Sep 2012
Posts: 70
Thanks: 1
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
This is not php - it is Javascript. Labrar used the wrong tags.

Code:
<script type = "text/javascript">
document.ontouchstart=document.onmousedown=preventer;
function preventer(e){    
if(!e){e=window.event;}
e.preventDefault();
}  
</script>

This piece of code does the trick in chrome, but in android simulator stops the app buttons and links from responding.

I wonder if it could be a matter of placement of the piece, but as I changed its location no chance resulted in either of the two environments.
eydg is offline   Reply With Quote
Old 11-14-2012, 06:51 PM   PM User | #9
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
If you just want to prevent dragging then this might work:

Code:
document.ontouchmove = function (e) {
    e.preventDefault();
};
..but I don't program for phones myself.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 11-14-2012, 06:56 PM   PM User | #10
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
If you want to continue to allow dragging of specific elements then it might be something like this:

Code:
document.ontouchmove = function (e) {
    var target = e.currentTarget;
    if (target.nodeName == 'IMG') {
        // or examine ID, etc..
       return;
    }
    e.preventDefault();
};
but, again, I'm not mobile
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 11-14-2012, 07:38 PM   PM User | #11
eydg
New Coder

 
Join Date: Sep 2012
Posts: 70
Thanks: 1
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
Thanks, but in either case, the screen keeps scrolling in Android simulation.
eydg is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:11 AM.


Advertisement
Log in to turn off these ads.