[英]How do I check if an element is visible and check if the URL contains a string using JQuery?
因此,我有一個包含#gallery-carousel-3的URL。 當用戶單擊右側圖標(.icon.icon-arrow-right)時,將添加.blocked類。 很好 但是,當用戶單擊左側圖標(.icon.icon-arrow-left)時,如果URL包含#gallery-carousel-3並且.panel-display div可見,則我想刪除.blocked類。 我似乎無法讓第二部分工作
我的代碼如下:
jQuery(document).ready( function($) {
$('.icon.icon-arrow-right').click(function(){
if(window.location.href.indexOf("#gallery-carousel-3") > -1 && $('.ad-panel').filter(':visible').length == 0 ) {
$('.owl-wrapper-outer').addClass('blockd');
}
});
$('.icon.icon-arrow-left').click(function(){
if(window.location.href.indexOf("#gallery-carousel-3") > -1 && $('.panel-display').is(':visible')) {
$('.owl-wrapper-outer').removeClass('blockd');
}
});
});
你可以在使用url哈希(#)的值: location.hash
因此,假設您的網址是http://example.com/#gallery-carousel-3
var urlHash = location.hash; // => #gallery-carousel-3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.