- This topic has 14 replies, 2 voices, and was last updated 5 years, 9 months ago by Tom.
-
AuthorPosts
-
July 14, 2018 at 12:39 pm #623734Max
Hi Tom et al
I need to remove two CSS classes from a html element based on screensize (media break points).
Note: I am not after
display:none:
I want the classes removed not hidden.
Can this be done with CSS?
If not is there a script snippet I can run in my footer hook.
Thanks for your assistance.
Kind Regards
Max
July 14, 2018 at 6:47 pm #623854TomLead DeveloperLead DeveloperHey Max,
I suppose you could use jQuery. This might be helpful: https://stackoverflow.com/questions/11047514/jquery-add-remove-class-when-window-width-changes
July 14, 2018 at 10:52 pm #623910MaxI tried the following:
(function($) { var $window = $(window), $html = $('html'); function resize() { if ($window.width() < 514) { return $html.addClass('mobile'); } $html.removeClass('mobile'); } $window .resize(resize) .trigger('resize'); })(jQuery);
However I get the following error:
Syntax Error Expecting T_VARIABLE
July 15, 2018 at 8:59 am #624268TomLead DeveloperLead DeveloperCan you link me to the page?
July 18, 2018 at 10:17 am #626794MaxI am using a lightbox plugin that injects a class into links for images. Works great.
Problem is I don’t want a light box for the images on tablet or mobile view.
To the best of my knowledge, @media settings are no help here?
I tried some wild ideas like
all:revert
but none of them worked.Plugin author hasn’t answered my two week old support topic.
What to do?
July 18, 2018 at 7:46 pm #627109TomLead DeveloperLead DeveloperThat javascript above is the right idea. It just needs to be tweaked to remove the correct classes.
July 19, 2018 at 12:39 am #627220MaxI want to put the javascript in the functions.php file in my child theme.
The plugin adds the following (2) classes to the html for a link:
<a href="https://mywebsite.com" class="venobox vbox-item">
I can’t get the snippet above to work.
What should the javascript look like?
July 19, 2018 at 10:18 am #627699TomLead DeveloperLead DeveloperSo in order to do this we would need to loop through each link on the page looking for that class.
In addition to that, we would need to run that loop continuously when resizing the page.
Performance-wise, this is a nightmare that I 100% wouldn’t do.
Unfortunately I don’t really have a solution for this off the top of my head.
July 19, 2018 at 10:37 am #627721MaxThe plugin has an option to turn off the “auto” add the classes to image links.
You can then add the classes manually in your html.
If I add the classes manually when I create a page, is there way to modify what screen size they will work on.
Thanks.
July 19, 2018 at 11:10 am #627742Max$(document).ready(function() { if (screen.width < 1024) { $('#some-id').unbind('click'); } });
Will this work?
https://stackoverflow.com/questions/14055352/disable-lightbox-in-responsive-design
July 19, 2018 at 7:52 pm #627990TomLead DeveloperLead DeveloperIt could:
jQuery(document).ready(function($) { if (screen.width < 1024) { $('.venobox').unbind('click'); } });
You could also just try this:
@media (max-width: 768px) { .venobox { pointer-events: none; } }
July 20, 2018 at 1:20 am #628138MaxThanks very much Tom.
Pointer-events is a good low fat solution.
How come no one mentioned it in all the stack and other articles I searched through?
July 20, 2018 at 9:14 am #628470TomLead DeveloperLead DeveloperNot sure – it’s not the greatest solution, but it works if you’re just trying to prevent clicks ๐
July 20, 2018 at 11:13 am #628581Max“It works” is good enough for me.
Thanks very much for your help.
July 20, 2018 at 4:41 pm #628800TomLead DeveloperLead DeveloperNo problem ๐
-
AuthorPosts
- You must be logged in to reply to this topic.