javascript - Jquery function with two events using &&
问题描述
$(document).ready(function () {
var scroll_start = 0;
var startchange = $('#heroSection');
var offset = startchange.offset();
$(document).scroll(function () {
scroll_start = $(this).scrollTop();
if (scroll_start > offset.top) && ($!(window).width()<760){
$('#myTopnav').css('background-color', 'rgba(0, 0, 0, 0.9)');
} else {
$('#myTopnav').css('background-color', 'transparent');
}
});
});
I'm trying to get this function to work only when there is a scroll event and the window is larger than 760px wide but can't seem to crack it.
解决方案
Try it like this
$(document).ready(function () {
var scroll_start = 0;
var startchange = $('#heroSection');
var offset = startchange.offset();
$(document).scroll(function () {
scroll_start = $(this).scrollTop();
if ((scroll_start > offset.top) && window.width > 760) {
$('#myTopnav').css('background-color', 'rgba(0, 0, 0, 0.9)');
} else {
$('#myTopnav').css('background-color', 'transparent');
}
});
});
You missed a "(" here
if **(**(scroll_start > offset.top) && window.width > 760){
推荐阅读
- google-sheets - 如果表列包含空单元格,则正确计算总行平均值
- python - http://localhost:5000/user/signup 404 未找到
- python - 读取和拆分 .csv 文件,其中包含带逗号的字符串
- python-3.x - 在 Python Tkinter 中使用按钮(和函数)更改变量
- git - 我从服务器上的 github 克隆我的项目时出错
- discord.js - 尝试执行一个不带前缀的 Discord.js 命令
- android - 如何通过后退按钮(箭头)将活动导航到片段?
- c - 拓扑排序 - 创建直接图问题
- c++ - 如何将 jbyteArray(或字节数组)写入 txt 文件 c++?
- ssh - Jsch - 在到 SLES15 服务器的单个会话中打开多个通道失败