How to start or stop the script at different resolutions?

0 like 0 dislike
5 views
Hello, tell me how this script adds a shadow and change the back with some background information, to start or stop at different screen resolutions?

For example, from the maximum width to 768 px this script is not working, and from 768 px and less work.
<!-- Фиксированная тень -->$(function(){$(window).scroll(function() {var top = $(document).scrollTop();if (top < 1) $('.topblock').css({'box-shadow':'none','background':'rgba(255,255,255,0.0)'});else $('.topblock').css({'box-shadow':'0 0 2px rgba(0,0,0,0.5)','background':'rgba(255,255,255,0.9)'});});});
by | 5 views

1 Answer

0 like 0 dislike
if ($(window).width() < 769) { $(window).scroll(function() { var top = $(document).scrollTop(); if (top < 1) $('.topblock').css({'box-shadow':'none','background':'rgba(255,255,255,0.0)'}); else $('.topblock').css({'box-shadow':'0 0 2px rgba(0,0,0,0.5)','background':'rgba(255,255,255,0.9)'}); }); } else { //do another }

I would also call when resize
$(window).on('resize', (function() { if ($(window).width() < 769) { $(window).scroll(function() { var top = $(document).scrollTop(); if (top < 1) $('.topblock').css({'box-shadow':'none','background':'rgba(255,255,255,0.0)'}); else $('.topblock').css({'box-shadow':'0 0 2px rgba(0,0,0,0.5)','background':'rgba(255,255,255,0.9)'}); }); } else { //do another } }));
by

Related questions

0 like 0 dislike
2 answers
asked Sep 6, 2019 by AleksandrB
0 like 0 dislike
2 answers
asked Aug 4, 2019 by AleksandrB
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
33,905 users