在小屏幕(或任何href链接)上禁用prettyphoto [英] disable prettyphoto on small screens (or any a href link)

查看:101
本文介绍了在小屏幕(或任何href链接)上禁用prettyphoto的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方法来禁用移动设备或任何其他小屏幕上的prettyphoto灯箱,并尝试了不同的脚本花费了数小时后,发现了一种非常简单的方法来处理CSS媒体查询:

I was looking for a way to disable prettyphoto lightbox on mibile devices or any other small screens and after spending hours by trying different script, I discovered a very simple way to do that with css media queries:

html

<div>
    <a class="lightbox" rel="prettyPhoto" href="img.jpg">
        <img src="img.jpg">
    </a>
</div>

css

@media all and (max-width: 479px) {
    a.lightbox {    
        pointer-events: none;
    }
}

但是,我只是想知道是否有更好的方法?使用JS函数(($(window).width())更好吗?我想确定它可以在任何设备上使用.谢谢.

But, I just like to know if there is a better (proper?) way? Is it better to use a JS functions ( ($(window).width() )? I want to be sure it will work on any devices. Thanks.

推荐答案

只需将其包装为:

if ($(window).width() >= 768) { 
    $("a[rel^='prettyPhoto']").prettyPhoto(); 
}

将起作用

这篇关于在小屏幕(或任何href链接)上禁用prettyphoto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆