Using media queries with jQuery -


i using jquery first time , have few div animations work great. however, on 720 p screen events fire @ wrong time, since there less pixels , event triggered via pixels scrolled. tried adapting code media queries, broke.

can help?

html sample:

<div class="textone">this text!</div> 

css:

.textone {   position:fixed;   top:8%;   left:-1000px;   z-index:4;   width:19%;   background:#99cc00;   border-radius:3px;   opacity:0.9;   font-size:1.3em;   color:#ffffff;   padding:1% 0.1% 1% 3.3%; } 

js:

jquery(document).ready(function ($) {     //this makes slidey things slide     //textone     if (window.matchmedia("(max-width: 1599px)").matches) {         // window width under 1599px         jquery(window).scroll(function () {             if (jquery(this).scrolltop() > 333 && jquery(this).scrolltop() < 1667) {                 jquery('.textone').stop().animate({ left: '0px' });             } else {                 jquery('.textone').stop().animate({ left: '-500px' });             }         });     } else {         // window width greater 1599px         jquery(window).scroll(function () {             if (jquery(this).scrolltop() > 500 && jquery(this).scrolltop() < 2500) {                 jquery('.textone').stop().animate({ left: '0px' });             } else {                 jquery('.textone').stop().animate({ left: '-500px' });             }         });     } } 

you should determine value want .textone appear programmatically, not hardcoded.

you can determine "333" , "1667" example offsettop of element on page or percent of height of page.

you can use jquerys .offset().top offset of elemenet top of window.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -