【发布时间】:2021-07-08 22:40:18
【问题描述】:
您好,我正在使用羽毛灯箱,需要它不要出现在平板电脑或移动设备上。我尝试使用来自Disable Lightbox in responsive design 的代码,但无法让它工作。代码如下:
$.noConflict();
jQuery( document ).ready(function( $ ) {
var lightbox = '<a href="http://info.ccfa.org/teamchallengetmm?&primary_source_code__c=internet&source_code_detail_1__c=ccteamchallenge.org&source_code_other__c=nottoolate_lightbox&which_event_are_you_interested_in__c=unknown&utm_source=tc_website&utm_medium=sitelink&utm_campaign=summer17&utm_content=nottoolate_lightbox&i_am_interested_in_=undecided"><img src="../images/content/pagebuilder/Summer17-Not-Too-Late-Lightbox-TC-Website.png "></a>';
function startLightbox(){
$.featherlight(lightbox);
}
console.log(getCookie("tc_lightbox"));
if(getCookie("tc_lightbox")){
}
else{
setCookie("tc_lightbox", 1);
setTimeout(startLightbox, 1500);
}
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
function setCookie(cname, cvalue) {
var d = new Date();
d.setTime(d.getTime() + (24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
});
.featherlight-content h1,h3{
margin:0;
}
.featherlight-content h1{
font-size:25px;
font-weight:bold;
}
.featherlight-content form input[type="text"], .featherlight-content form input[type="email"]{
width:100%;
height: 34px;
border: 1px #757576 solid;
border-radius: 3px;
font-size: 16px;
font-family: 'avenirroman';
color: #999;
background-color: #fff;
}
.featherlight-content form input[type="submit"]{
width:100%;
cursor:pointer;
background: #f37736;
padding: 10px 25px;
color: #fff;
font-family: 'avenirblack', Arial Black;
font-size: 20px;
text-decoration: none;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border: none;
}
.featherlight .featherlight-content {
background: transparent !important;
}
@media only screen and (max-width: 767px) {
.featherlight img {
max-width: 100%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
我也试过
if ($(window).width() < 960) {
$(lightbox).hide();
}
并在使用 css 的媒体查询中使用 display: none
有什么想法吗?
【问题讨论】:
标签: javascript jquery