If Else JQuery error
If Else JQuery error
我已经成功编辑了一个wordpress, woocommerce js文件。但是,当我尝试更改标准滚动功能以首先检查浏览器宽度时,它会因意外的标记(错误)而失败。我看不出问题在哪里,我试过好几种重写方法。我正在尝试的代码是:
// Scroll to top
$( 'html, body' ).animate( {
if( $(window).width() < 680 ) {
scrollTop: ( $( 'form.checkout' ).offset().top - 100 )
}, 1000;
else {
scrollTop: ( $( 'form.checkout' ).offset().top - 170 )
}, 1000;
}
在animate
调用之前进行条件检查-而不是在它内部!
if( $(window).width() < 680 ) {
$( 'html, body' ).animate( {
scrollTop: ( $( 'form.checkout' ).offset().top - 100 )
});
} else {
$( 'html, body' ).animate( {
scrollTop: ( $( 'form.checkout' ).offset().top - 170 )
});
}
或者另一种方法:
var offset = ($(window).width() < 680) ? 100 : 170;
$( 'html, body' ).animate( {
scrollTop: ( $( 'form.checkout' ).offset().top - offset)
});
相关文章:
- jQuery Error adadvisor.net
- Jquery Animate on IE makes error
- jquery ajax delete 404 error
- JQuery Error在出现错误时加载备用映像的事件
- jQuery slideDown() error
- jQuery error()函数在IE中不起作用
- jquery.rotate error
- 在jQuery 1.8及以上版本中键入error
- jQuery fadeToggle() error
- jQuery insertBefore error with Internet Explorer
- ajax jquery 始终运行 Error;.
- jQuery $.ajax post getting referer url for error debugging
- jQuery for HTML to PHP - Function Error
- jQuery ajax:error 即使响应为 OK 200 也会运行
- WebSQL: jQuery for each error
- Internet Explorer JQuery Error
- Struts 2 jquery plugin javascript error
- Jquery error() 在 chrome 和 IE 中工作,但不能在 Firefox 中工作
- net::ERR_CONNECTION_REFUSED Error jQuery ajax node.js
- parseJSON error (jQuery 1.7.2)