Contact Us

|

FriendFeed FriendFeed

|

follow us on twitter Twitter

|

 Rss Feed

|

Favorites Add to Favorites

Friday, July 13, 2012

How to disable or enable window's scroll or key events?

When you try to write a simple java script for overlay or popup message, you might find it odd when the background content scrolls when user try to scroll it using mouse or keyboard. So here is a simple java script to disable it....

   // left: 37, up: 38, right: 39, down: 40,
   // spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36

   var keys = [37, 38, 39, 40];

   function preventDefault(e) {
     e = e || window.event;
     if (e.preventDefault)
     e.preventDefault();
     e.returnValue = false;  
   }

   function keydown(e) {
       for (var i = keys.length; i--;) {
           if (e.keyCode === keys[i]) {
               preventDefault(e);
               return;
           }
       }
   }

   function wheel(e) {
     preventDefault(e);
   }

   function disable_scroll() {
     if (window.addEventListener) {
         window.addEventListener('DOMMouseScroll', wheel, false);
     }
     window.onmousewheel = document.onmousewheel = wheel;
     document.onkeydown = keydown;
   }

   function enable_scroll() {
       if (window.removeEventListener) {
           window.removeEventListener('DOMMouseScroll', wheel, false);
       }
       window.onmousewheel = document.onmousewheel = document.onkeydown = null;  
   }

Call disable_scroll() from the code above before animation and enable_scroll() after the animation ended.

Labels: , , , , , ,

79 Comments:

Anonymous Blogfreakz said...

this really saves me a lot of headache awesome tutorials

March 14, 2013 at 8:18:00 PM PDT  
Blogger Vinod Kumar said...

Thank you sharing this information thank you.Come back again for more interesting stuffs like one you got earlier!Bulk SMS India

July 29, 2013 at 4:53:00 AM PDT  
Blogger Samantha Razil said...

Thanks for the info!! web designing company

August 6, 2013 at 10:31:00 PM PDT  
Blogger Deeksha Housing said...

Thanks so much for this helpful information come back again for more interesting information…Keep it up
Builders in Agra

August 16, 2013 at 6:10:00 AM PDT  
Blogger Neha Sharma said...

Nice blog! Very interesting and informative post….Thank's for sharing such a nice information….Keep it up!!! Website Designing in Agra

August 26, 2013 at 2:02:00 AM PDT  
Blogger steev frank said...

I have learnt many things from you web designer in Toronto thank you very much sir..

October 9, 2013 at 10:12:00 AM PDT  
Blogger Thiru Moorthy said...

Thanks for your grateful informations, am working in Web Design Company in Bangalore

October 17, 2013 at 8:45:00 PM PDT  
Blogger Sonia Rai said...

Hi Grat Your Blog,Thank's for this helpful information come back again for more interesting information!!!
Event planners in Delhi

October 21, 2013 at 3:54:00 AM PDT  
Blogger Hakim Bohari said...

Hi there! Great post. Thanks for sharing a very interesting and informative content.

October 23, 2013 at 11:22:00 PM PDT  
Blogger nishu kumar said...

Thanks sir. It's awesome ,it is realy helpful

Searchinfomedia

November 21, 2013 at 9:12:00 PM PST  
Blogger nishu kumar said...

Thanks sir. It's awesome ,it is realy helpful

Searchinfomedia

November 21, 2013 at 9:17:00 PM PST  
Blogger nishu kumar said...

Thanks. It's awesome ,it is realy helpful

Searchinfomedia

November 21, 2013 at 9:26:00 PM PST  
Blogger anshu kr said...

Thanks for the sharing of such information. we will pass it on to our readers. This is a great reading. Thanking you.
Searchinfomedia

November 25, 2013 at 9:17:00 PM PST  
Blogger anshu kr said...

Thanks for the sharing of such information. we will pass it on to our readers. This is a great reading. Thanking you.
Searchinfomedia

November 25, 2013 at 9:19:00 PM PST  
Blogger anshu kr said...

Thanks for sharing these information's your tips are really good.

Searchinfomedia

November 25, 2013 at 9:31:00 PM PST  
Blogger Renato Crespo said...

Nice information . You have included really nice information that will be helpful to me . Thanks to share this information.
Diseño web asturias

November 26, 2013 at 9:46:00 PM PST  
Blogger Mike Lowson said...

I'm extremely impressed together with your writing talents as neatly as with the structure in your weblog. Is this a paid topic or did you modify it yourself? Either way stay up the excellent quality writing, it's rare to peer a nice blog like this one today.
Top Five Firefox Add-ons – You will love these

November 29, 2013 at 7:35:00 PM PST  
Blogger minu srivastav said...

Thanks for the sharing of such information. we will pass it on to our readers. This is a great reading. Thanking you.
Searchinfomedia

December 4, 2013 at 11:58:00 PM PST  
Blogger andrew vatts said...

This comment has been removed by a blog administrator.

December 13, 2013 at 10:04:00 PM PST  
Anonymous Web designing and development said...

Very nice posting you create in your blog, I ever wish to read this type of topics about creative solution.

December 20, 2013 at 1:00:00 AM PST  
Anonymous web design india said...

Its so informative web blog,You have share such a very informative article in this blog

January 11, 2014 at 8:15:00 PM PST  
Blogger Andrew Mediaura said...

This comment has been removed by the author.

February 7, 2014 at 2:19:00 AM PST  
Blogger Cameron Williams said...

Your post is very great!..So informative, I’m gonna try this. Thanks for sharing. perfiles para tablaroca

April 10, 2014 at 3:08:00 AM PDT  
Blogger james neesham said...

I am very glad to get this kind of useful information from this blog.Its really interesting. web development company hawaii

April 16, 2014 at 10:12:00 PM PDT  
Blogger Kane Anderson said...

Thank For Good information of Great for me. captain america gifts

April 22, 2014 at 10:11:00 PM PDT  
Blogger james neesham said...

This nice & useful blog….Thanks for this post Thanks for posting this informative blog…well done. web development company hawaii

April 24, 2014 at 10:41:00 PM PDT  
Blogger Darren Harris said...

Your Blog is very good, I like it! Thank you for you sharing!Your blog is really helps for my search and i really like it. sexual addiction treatment

April 28, 2014 at 3:37:00 AM PDT  
Blogger Glenn Ponting said...

Wow, this is great information. trauma treatment

April 30, 2014 at 4:06:00 AM PDT  
Anonymous Web Development said...

Hmm....Gr8 efforts!!

May 22, 2014 at 2:57:00 AM PDT  
Anonymous best Web design company in Lucknow said...

Thanks for sharing this- good stuff! Keep up the great work, we look forward to reading more from you in the future!  

June 16, 2014 at 10:55:00 PM PDT  
Anonymous M2softsolutionsPvt. ltd said...

nice article... thank you for sharing...

June 21, 2014 at 4:24:00 AM PDT  
Blogger Pushpendra Yadav said...

WOW What a great post, this post is very useful in website designing and provide a good resource for designers.

July 2, 2014 at 6:02:00 AM PDT  
Anonymous Web design company  in Noida said...

useful information. Thanks for sharing.

September 29, 2014 at 10:27:00 PM PDT  
Anonymous web development Philippines said...

Thanks for this. Such a help. :)

October 25, 2014 at 5:45:00 PM PDT  
Blogger Olivia Crespo said...

Thanks for sharing this informative blog post, I think that these tips are really useful and increase our knowledge. I have face this problem many time. Thanks for give this problem permanent solution. Thanks for this post.
Brand development

November 2, 2014 at 5:24:00 AM PST  
Blogger Wizard Infoways said...

Thanks for sharing the information.

Web Development Services in Delhi

November 12, 2014 at 1:40:00 AM PST  
Anonymous best Web design company in Lucknow said...

It is very useful content .. Thanks for posting

December 3, 2014 at 9:44:00 PM PST  
Blogger David Miller said...

For Custom Website Development Services in san diego, contact effetcual technology @ www.effectualtech.com

December 17, 2014 at 8:57:00 PM PST  
Blogger Akash Chauhan said...

Thank you for sharing valuable information. Good website design and development but cheap rate visit us : Software Development Company Jaipur

December 19, 2014 at 3:11:00 AM PST  
Blogger Trilogeek said...

Thanks for this tutorial do you know a good web development company in the Philippines

December 23, 2014 at 3:42:00 AM PST  
Blogger Priyadarshini Mohapatra said...

Nice blog.Thanks for sharing.
web development and design service

December 27, 2014 at 12:17:00 AM PST  
Anonymous Omega Softwares said...

Good one ........i really like this post...... CMS Website Design || Website Development


December 28, 2014 at 11:44:00 PM PST  
Anonymous Omega Softwares said...

This is very useful information. Thank you for sharing with us.
Website Development in Mumbai

December 28, 2014 at 11:48:00 PM PST  
Anonymous osiel webs said...

Find Your Solutions
PPC Expert For Tech Support
ppc tech support

ppc management experts | technical support ppc expert

December 29, 2014 at 8:37:00 AM PST  
Blogger Michael John said...

Thanks for sharing .

seo services company

December 30, 2014 at 12:44:00 AM PST  
Blogger Omega software said...

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck. Website Development in Mumbai || CMS Website Developer || Website Maintenance in Mumbai

January 7, 2015 at 11:55:00 PM PST  
Blogger Omega software said...

This post is very helpful, edifying and in addition cool thoughts on the topic. It's very encouraging to find this site, can't wait to check out new stuff you post. CMS website development company || Web Designing || Website Development

January 7, 2015 at 11:56:00 PM PST  
Blogger Compaddicts Infotech said...

Thanks for your grateful informations
Ssoftware development company Lucknow

January 19, 2015 at 4:50:00 AM PST  
Blogger Seo Company Bhubaneswar said...

Great Post. I was truly delighted to read this. Things seem to be crystal clear now..................Scorpio Technologies is a Professional web development bhubaneswar Company.We are the Experts in the web development World and fullfils our Customers requirements in a Strategic Way.We offers wide range of web application development services such as CMS, E-commerce and ERP development to customers and strive hard to mark their inevitable presence in the World Wide Web.

Web Development Bhubaneswar

January 23, 2015 at 3:39:00 AM PST  
Blogger Liam Rowe said...

Providing effective Web Development Dubai web design to improve the customers for websites. Business people develop websites for world wide business. Giving impressible graphics to website full fill the customer needs.

March 6, 2015 at 8:52:00 AM PST  
Blogger Red Logics said...

Thanks for sharing informative post. Web Development Company India

March 10, 2015 at 12:10:00 AM PDT  
Blogger Raj Solanki said...

Thanks for helping us with wonderful article posted in this blog. I love to read articles which are informative and useful.
Website Development Indore | Web Development Company in Indore | Web Development Company Indore

March 30, 2015 at 4:27:00 AM PDT  
Blogger Liam Rowe said...

Providing effective Web Development Dubai web design to improve the customers for websites. Business people develop websites for world wide business. Giving impressible graphics to website full fill the customer needs.

April 17, 2015 at 10:42:00 AM PDT  
Blogger Krsitconsulting said...

Nice Post.
Valuable and interesting information.
Thanks for sharing with us.
Website development


April 20, 2015 at 11:48:00 PM PDT  
Blogger Rgb Dzine said...

great, thank you for sharing, it's really informative...

Best Web Development Company

May 28, 2015 at 12:04:00 PM PDT  
Blogger Sanjay Kumar said...

NIce post. good information
If you are Looking for web development service, Web Development Services Delhi, best SEO company in Delhi , SMO Service or internet marketing services? Get in touch with us and we provide you the best solution to your requirement.

June 13, 2015 at 9:44:00 PM PDT  
Blogger zain said...

Find best web development company Australia
Our Web design value Packages are Flexible and Effective. Customised attention to details in Web Design & Development Process helps us reach your Target Audience at a Personal Level which enables Call to Action from your clients.We Believe a Website should be visually appealing as well as Effective in generating convertible leads for you.Talk to us today to find out how you can add value to your business and how we can help you welcome your customers to your online door step.

July 22, 2015 at 2:07:00 AM PDT  
Blogger Varun Mishra said...

Thanks for sharing
website development India

July 24, 2015 at 5:40:00 AM PDT  
Blogger Sonia Danial said...

Thanks for such a nice post. Send an Enquiry at Technotips is a leading software company among Software Companies in Bhubaneswar . If any type of requirement of Application Software, Website Design & Development, SEO, SMO Service, Ad Posting Service . SEO & Website Starts from 100$ onwards.

August 12, 2015 at 6:04:00 AM PDT  
Blogger Balajinavo SEO said...

Really an interesting and amazing post. Thanks for sharing this wonderful informative article here. I appreciate your hard work.SEO Companies | Digital Marketing Company Bangalore

August 30, 2015 at 11:15:00 PM PDT  
Blogger Elina said...

I really would like to praise you for writing such a fabulous article Thanks for your great blog about website promoting site.


Affordable SEO Company in India & Best Organic SEO Services

September 3, 2015 at 3:13:00 AM PDT  
Blogger Techno Tips said...

Nice Post, Thank you for such a post. Technotips is the Best Web Design Company in Bhubaneswar, which provides Domain Registration, Web Hosting, Web Design & Development Service. Visit us & choose your Design.

December 21, 2015 at 11:53:00 PM PST  
Anonymous Digital Marketing Link Builder said...

Excellent post.Thanks for sharing this message.Really,Your blog is not only instructive but useful too. SEO Company Chennai

January 7, 2016 at 2:52:00 AM PST  
Blogger flymedia technology said...

Really nice post thankss for the sharing with us. If anyone wants the low cost Ecommerce Website Development in Punjab the visit ton our website.

March 1, 2016 at 11:32:00 PM PST  
Blogger Nexevo Technologies http://www.nexevo.in said...

Nexevo Technologies is the best website design and development company Bangalore.For more information: Website Design Agency Bangalore | SEO Bangalore

March 15, 2016 at 3:01:00 AM PDT  
Blogger Zinavo Bangalore said...

It was very useful for me. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing the such information with us. Web Design Company Bangalore | Website Design Bangalore

May 23, 2016 at 3:31:00 AM PDT  
Blogger Sathya G said...

Wanna great article that very useful. All things which specify is a very interesting for read.SEO Company in Chennai

June 21, 2016 at 1:43:00 AM PDT  
Blogger WEB SEO COMPANY INDIA said...

Hello my friend! I wish to say that this article is amazing, nice written and include almost all important information. I would like to see more posts like this. Local SEO Agency India

July 21, 2016 at 11:12:00 PM PDT  
Blogger Bangalore Web Guru said...

Great amazing blog your Web Design and development process starts with a focus on your online priorities -- raising money, inspiring activism, building a community of supporters, education and awareness, etc..........Website Development Bangalore | Website Designing Company Bangalore

July 25, 2016 at 3:56:00 AM PDT  
Blogger Priya Gupta said...

Good efforts. All the best for future posts. I have bookmarked you. Well done. I read and like this post. Thanks. best mba colleges in punjab

November 27, 2016 at 8:26:00 PM PST  
Blogger Redspider Design said...

Great tips there. I'll certainly take note of that. Thanks......Graphics Designing Company in Dubai

December 29, 2016 at 1:39:00 AM PST  
Blogger hari andro said...

Thanks for giving details about how to enable and disable windows scroll ..Keep posting useful tips for windows like this.
Engineering Colleges In Chennai , Nautical Science Colleges In Chennai

February 8, 2017 at 6:45:00 AM PST  
Blogger edward john said...

Many of the people don’t know the scope of windows development. It is a creative and interesting part of every web and app development. This article is very helpful to understand all windows development concepts..
Dubai cooking school , International Centre for Culinary Arts

February 19, 2017 at 11:17:00 PM PST  
Blogger katie middleton said...

I really loved reading your blog. It was very well authored and easy to understand.Old Age Home in Coimbatore, Charitable Trust in Coimbatore


February 23, 2017 at 2:26:00 AM PST  
Blogger katie middleton said...

This is really nice because it well informative for me and hope for others also keep it continued so that we can get benefits.Hotels in Kumbakonam,Budget Hotels in Kumbakonam

February 27, 2017 at 2:58:00 AM PST  
Blogger katie middleton said...

The article is very interesting and truly informative. Thanks for sharing. Keep more sharing.Hotels in Kumbakonam,Kumbakonam Hotels

March 11, 2017 at 2:31:00 AM PST  
Blogger katie middleton said...

Marvelous! Great post. I am one of blogger in this blog .I like all posts here. Thank you.SPA IN KUMBAKONAM, SPA IN TRICHY, SPA IN THANJAVUR

April 7, 2017 at 2:46:00 AM PDT  
Blogger katie middleton said...

I am really happy while reading your post, Thanks to make me happy,ITFOFINDIA,ITF OF INDIA

April 19, 2017 at 2:43:00 AM PDT  
Blogger Kanye Co Jamila said...

An important building block of SEO is to develop your website which can be easily understandable for both Online Visitors (most important) and search engine robots. In the current digital age, seo is important for your online success means to generate leads.

SEO Services in IndiaSEO Company in India SEO Company in India SEO Services in India

SEO Company in India SEO Services in India

May 6, 2017 at 12:22:00 AM PDT  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home