簡體   English   中英

基於CSS媒體查詢加載jquery腳本

[英]Load jquery script based on CSS media query

當前行為:移動版本上的所有鏈接,正在新窗口中加載。 但是,桌面版可以正常工作。 嘗試使用“ _self”,無法正常工作。

預期行為:移動鏈接必須在同一窗口中打開,並且不應影響其他燈箱或彈出窗口行為。 另外,桌面版。

如果@media screen and (max-width: 767px)有沒有一種方法可以將鏈接定位為停止傳播或返回false?

如果我使用e.stopPropgation()或返回false,則會通過重定向到“未定義”來影響我的桌面版本鏈接和燈箱以及所有其他觸發操作。

根據您的兼容性需求,一種解決方案是使用window.matchMedia()

if (window.matchMedia("(min-width: 400px)").matches) {
  /* the view port is at least 400 pixels wide */
} else {
  /* the view port is less than 400 pixels wide */ 
  $('.your-link-class').click(function (event) {
    event.stopPropagation();
    return false;
  })
}
if ($(window).width() < 768) {
   alert('Less than 768');
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM