disable prettyphoto on small screens (or any a href link)

荒凉一梦 提交于 2019-12-24 23:17:10

问题


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;
    }
}

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.


回答1:


Just wrap it with:

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

will work



来源:https://stackoverflow.com/questions/28657665/disable-prettyphoto-on-small-screens-or-any-a-href-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!