我有一些按钮,onclik滚动到内容,这段代码运行良好:
jQuery(document).ready(function(){
jQuery("button#defaultOpen").click(function() {
jQuery('html, body').animate({
scrollTop: jQuery("#defaultOpen").offset().top+267
}, 1000);
});
jQuery("button#spezialkurs").click(function() {
jQuery('html, body').animate({
scrollTop: jQuery("#spezialkurs").offset().top+267
}, 1000);
});
jQuery("button#opengym").click(function() {
jQuery('html, body').animate({
scrollTop: jQuery("#opengym").offset().top+125
}, 1000);
});
jQuery("button#challenge").click(function() {
jQuery('html, body').animate({
scrollTop:jQuery("#challenge").offset().top+125
}, 1000);
});
jQuery("button#vielseitige").click(function() {
jQuery('html, body').animate({
scrollTop: jQuery("#vielseitige").offset().top-10
}, 1000);
});
});问题是,我想添加媒体查询,这段代码只能在768以上运行!或者这里有更多的错误?
谢谢,
发布于 2017-08-23 22:43:17
您可以使用类似以下内容:
if (screen.width > 768) {your code goes here}发布于 2017-08-23 22:44:00
你不能在jQuery中使用媒体查询,但是如果你只想运行你的函数来获得特定的解析,你可以使用下面的代码:
if(jQuery(window).width() > 768) {
your code
}https://stackoverflow.com/questions/45842820
复制相似问题